Loop three lists at the same time?
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Tue Nov 13 06:00:00 EST 2007
En Tue, 13 Nov 2007 07:46:09 -0300, Davy <zhushenli at gmail.com> escribió:
> I have three lists with the same length. Is there any method to loop
> the three lists without a loop counter?
Try zip or itertools.izip:
py> L1 = ['a','b','c']
py> L2 = [1, 2, 3]
py> L3 = ['I', 'II', 'III']
py> from itertools import izip
py> for x,y,z in izip(L1,L2,L3):
... print x,y,z
...
a 1 I
b 2 II
c 3 III
--
Gabriel Genellina
More information about the Python-list
mailing list