Python style.
Johann Hibschman
johann at physics.berkeley.edu
Wed May 10 11:18:32 EDT 2000
Markus Stenberg writes:
> "Fredrik Lundh" <effbot at telia.com> writes:
> <snip>
>> for item1 in list1; item2 in list2:
>> ...
>>
> Ugh.. that looks bit obscure - why sudden use of ; for example?
> I'd like something like
> for item1, item2 in list1, list2:
> That'd be consistent with current tuple action as well, and just some
> appearance-related glue compared to the normal map(None, list1, list2)
> case.
Actually, no, not really. The problem is that "list1, list2" is
already a valid tuple-building expression, so we can't use that as
special syntax. People happliy write
for i in 1, 2, 3:
print i
What you really want is something like:
for item1, item2 in transpose((list1, list2)):
to go from a tuple of two lists to a list of many tuples. That's what
that awful map None does.
--Johann
--
Johann Hibschman johann at physics.berkeley.edu
More information about the Python-list
mailing list