D
Dave Dean
Hi all,
I'm looking for a way to iterate through a list, two (or more) items at a
time. Basically...
myList = [1,2,3,4,5,6]
I'd like to be able to pull out two items at a time - simple examples would
be:
Create this output:
1 2
3 4
5 6
Create this list:
[(1,2), (3,4), (5,6)]
I want the following syntax to work, but sadly it does not:
for x,y in myList:
print x, y
I can do this with a simple foreach statement in tcl, and if it's easy in
tcl it's probably not too hard in Python.
Thanks,
Dave
I'm looking for a way to iterate through a list, two (or more) items at a
time. Basically...
myList = [1,2,3,4,5,6]
I'd like to be able to pull out two items at a time - simple examples would
be:
Create this output:
1 2
3 4
5 6
Create this list:
[(1,2), (3,4), (5,6)]
I want the following syntax to work, but sadly it does not:
for x,y in myList:
print x, y
I can do this with a simple foreach statement in tcl, and if it's easy in
tcl it's probably not too hard in Python.
Thanks,
Dave