[Python-Dev] list comprehensions again...

Guido van Rossum guido@beopen.com
Tue, 11 Jul 2000 12:52:43 -0500

Oops.  I was simply mistaken on what the for-for syntax in list
comprehensions did!

Ideally, list comprehensions should support both parallel and nested
for loops, but I'm not sure how to decide to parse them if they both
occur.  E.g. what is this?

  [(x,y+z) for x in (1,2,3,4,5,6); for y in "abc" for z in "de"]

For me, the semicolon separates much stronger than the for, so (to me)
this feels like (applying parentheses to show grouping):

  (for x); (for y for z)

and would yield:

  [(1, "ad"), (2, "ae"), (3, "bd"), (4, "be"), (5, "cd"), (6, "ce")]

But is that the most useful?  And how do you write the other grouping?
I mean:

  (for x; for y) (for z)

which could yield:

  [(1, "ad"), (1, "ae"), (2, "bd"), (2, "be"), (3, "cd"), (3, "ce")]

A more practical question: if we're going to introduce [::], list
comprehensions, and parallel for loops, what would be the best way to
introduce the patches so that each patch changes as little as possible
of the code introduced by the previous patch?

--Guido van Rossum (home page: http://dinsdale.python.org/~guido/)