In the documentation, the definition of the generator expression reads
generator_expression ::= "(" expression comp_for ")"
whereas in the grammar it is hidden and reads
atom: ('(' [yield_expr|testlist_comp] ')' | .......
testlist_comp: (test|star_expr) ( comp_for | (',' (test|star_expr))* [','] )
According to the grammar, "(" "*" expression comp_for ")" is a valid generator expression but is is not detailed in the documentation. Can someone point me to a concrete example for this kind of generator with a star.
Assuming myList = ((1, 2, 3), (4, 5, 6))
, consider for example (*x for x in myList)
myList
is an atomfor x in myList
matches comp_for according tocomp_for: 'for' exprlist 'in' or_test
*x
matchesstar_expr
thustest|star_expr
*x for x in myList
matchestestlist_comp
- finally
(*x for x in myList)
is a valid atom because it matches'(' testlist_comp ')'
The python interpreter gives SyntaxError: iterable unpacking cannot be used in comprehension