list comprehensions whats happening here

Alex Martelli aleaxit at yahoo.com
Fri Apr 13 12:01:56 EDT 2001


"Emile van Sebille" <emile at fenx.com> wrote in message
news:9b71c7$7sse3$1 at ID-11957.news.dfncis.de...
> I suspect the answer lies somewhere in the comma converting the parts of
the
> list comprehension into a list itself, much as the comma is used in normal
> iteration idiom:
>
> for i in 1,2

Bingo!  The rule is the same: "parentheses don't make tuples,
COMMAS make tuples" [with the sole exception of the empty
tuple, whose literal form is comma-less].  E.g., note the
difference the comma makes here:

>>> for x in 'ciao',:
...   print x
...
ciao
>>> for x in 'ciao':
...   print x
...
c
i
a
o
>>>


Alex








More information about the Python-list mailing list