Multiple tuples for one for statement

Kent Johnson kent37 at tds.net
Sun Apr 24 23:24:48 EDT 2005


Harlin Seritt wrote:
> I have three tuples of the same size: tup1, tup2, tup3
> 
> I'd like to do something like this:
> 
> for a,b,c in tup1, tup2, tup3:
>    print a
>    print b
>    print c

Presuming that you want a,b,c to be corresponding entries from the three tuples, then zip() is your 
friend:
for a,b,c in zip(tup1, tup2, tup3):
   ...

Kent



More information about the Python-list mailing list