Multiple tuples for one for statement
Steven Bethard
steven.bethard at gmail.com
Sun Apr 24 23:24:22 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
>
> Of course, you get an error when you try to run the pseudocode above.
> What is the correct way to get this done?
for a, b, c in zip(tup1, tup2, tup3):
print a
print b
print c
If your tuples become iterators, look into itertools.izip.
STeVe
More information about the Python-list
mailing list