looping through two list simultenously

Daniel Nogradi nogradi at gmail.com
Sun Oct 29 15:41:15 EST 2006


> folks
> I have two lists
>
>  i am trying to loop thorough them simultenously.
>
> Here is the code i am using

[...]

> Is there any efficient doing this
>

Try the zip function:

>>> list1 = [ 'a', 'b', 'c' ]
>>> list2 = [ 'A', 'B', 'C' ]
>>> for i, j in zip( list1, list2 ):
...     print i, j
...
a A
b B
c C



More information about the Python-list mailing list