Syntax for simultaneous "for" loops?

Alex Martelli aleaxit at yahoo.com
Mon Feb 17 06:32:31 EST 2003


John Ladasky wrote:   
   ...
> A few days ago I came across a web page which described a "for"
> syntax, which allowed two variables to be stepped at the same time,
> through two independent lists.  I said to myself, "that's cool, I
> wonder when I might need that?"  Well, I need it now.  But I
> bookmarked the relevant web page at work, and we're snowed in here!
> 
> Would some kind soul please point me to the relevant information?


for onevar, another in zip(onelist, otherlist):
    print onevar, another

may be what you want -- the two lists are iterated "in parallel".


Alex





More information about the Python-list mailing list