Paul Moore wrote:
Where in [fn(x) for x in lst if cond] is the *
allowed? fn(*x)? *fn(x)?

Obviously you're *allowed* to put fn(*x), because that's
already a valid function call, but the only *new* place
we're talking about, and proposing new semantics for, is
in front of the expression representing items to be added
to the list, i.e. [*fn(x) for ...]

I think it's probably time for someone to
describe the precise syntax (as BNF, like the syntax in the Python
docs at


   comprehension ::=  expression comp_for


   comprehension ::=  (expression | "*" expression) comp_for

and semantics (as an explanation of how to
rewrite any syntactically valid display as a loop).

The expansion of the "*" case is the same as currently except
that 'append' is replaced by 'extend' in a list comprehension,
'yield' is replaced by 'yield from' in a generator

If we decided to also allow ** in dict comprehensions, then
the expansion would use 'update'.

Python-ideas mailing list
Code of Conduct:

Reply via email to