Python: use izip for iterating over multiple lists

I know I'll forget this again, so I'll blog it.
from itertools import izip

xlist = [1, 2, 3]
ylist = [5, 6, 7]

for x, y in izip(xlist, ylist):
print x, y

Outputs:
1 5
2 6
3 7
This also works for more than two lists. Zip() and map() also work but izip() should use less memory and perh

Comments

Popular posts from this blog

Shortest Sudoku solver in Python

Dot to Png

Seven Segment Display in Inkscape