[Python-Dev] Re: PEP 289: Generator Expressions (second draft)

Werner Schiendl ws-news at gmx.at
Thu Oct 23 11:47:24 EDT 2003


Hello,

this is my first post to this list, but I followed it "passive" since quite
some time.

I had a thought about distinguishing the list with 1 iterators vs. list
comprehension issue that did not appear (at least to my eyes) yet.


Why not take the same approach than used for tuples already?

like (5) is just the value 5 and (5,) is a 1-tuple containing the value 5

I thought it would be intuitive to have

[x**2 for x in range(n)]  # be a list comprehension like it currently is
[x**2 for x in range(n),]  # a list with 1 iterator in it

> No, it's a set comprehension where the set elements are pairs.  The dict
> comprehension would be
>
> {x: x**2 for x in range(n)}
>
> Or would that be a single-element dict whose key is x and value is a
> generator expression?  :-)

in this case the same could be applied

{x: x**2 for x in range(n)}  # dict comprehension
{x: x**2 for x in range(n),}  # dict with 1 iterator (but "x" is probably
not a valid name, is it?)


best regards

Werner







More information about the Python-Dev mailing list