[Python-ideas] Fwd: Fwd: unpacking generalisations for list comprehension
Greg Ewing
greg.ewing at canterbury.ac.nz
Fri Oct 14 01:23:32 EDT 2016
Steven D'Aprano wrote:
> py> def gen():
> ... for t in [(1, 'a'), (2, 'b'), (3, 'c')]:
> ... yield *t
> File "<stdin>", line 3
> yield *t
> ^
> SyntaxError: invalid syntax
>
> Even if it was allowed, what would it mean? It could only mean "unpack
> the sequence t, and collect the values into a tuple; then yield the
> tuple".
To maintain the identity
list(*x for x in y) == [*x for x in y]
it would be necessary for the *x in (*x for x in y) to expand
to "yield from x".
--
Greg
More information about the Python-ideas
mailing list