Loop three lists at the same time?

J. Robertson jr244 at kent.ac.uk
Tue Nov 13 05:53:12 EST 2007


Davy wrote:
> Hi all,
> 
> I have three lists with the same length. Is there any method to loop
> the three lists without a loop counter?
> 
> Best regards,
> Davy
> 

Hello,

the zip function?

>>> list1 = [1,2,3]
>>> list2 = [4,5,6]
>>> list3 = [7,8,9]
>>> for a,b,c in zip(list1,list2,list3):
...    print a, b, c
...
1 4 7
2 5 8
3 6 9

hth
j.



More information about the Python-list mailing list