[Python-Dev] zip() and list-comprehension with commas
Paul Prescod
paul@prescod.net
Wed, 12 Jul 2000 04:44:07 -0500
Ka-Ping Yee wrote:
>
>
> As for the SyntaxError, i think it's a good idea because the
> example could be ambiguous. You would have to either say
>
> [(x, y), for x in list1, if x > 1, for y in list2, if y > 2]
>
> or
>
> [x] + [y, for x in list1, if x > 1, for y in list2, if y > 2]
The easy way to avoid the ambiguity is to dump the comma and use colons
as Guido intended.
[for x in list1:
if x > 1:
for y in list2:
if y > 2:
(x,y)]
--
Paul Prescod - Not encumbered by corporate consensus
Simplicity does not precede complexity, but follows it.
- http://www.cs.yale.edu/~perlis-alan/quotes.html