Multiple tuples for one for statement
Peter Hansen
peter at engcorp.com
Mon Apr 25 10:10:51 EDT 2005
Ivan Van Laningham wrote:
> "R. C. James Harlow" wrote:
>>On Monday 25 April 2005 14:34, Ivan Van Laningham wrote:
>>>"R. C. James Harlow" wrote:
>>>>or just:
>>>>
>>>>for a,b,c in (tup1, tup2, tup3):
>>>> print a
>>>> print b
>>>> print c
>>>
>>>And this works in Python version???
>>
>>Ah, reading the replies to the original post, this works but doesn't give the
>>result that the original poster wanted.
>
> Define "works":
>>> a = (1,2,3)
>>> b = ('a','b','c')
>>> c = (None, 'foo', 3.14)
>>> tup1 = (1,2,3)
>>> tup2 = ('a','b','c')
>>> tup3 = (None, 'foo', 3.14)
>>> for a,b,c in (tup1,tup2,tup3):
... print a
... print b
... print c
...
1
2
3
a
b
c
None
foo
3.14
>>>
It's a valid interpretation of the OP's
ambiguously stated requirements, though probably
not the right one.
-Peter
More information about the Python-list
mailing list