Apr-09-2023, 08:05 AM
(This post was last modified: Apr-09-2023, 08:06 AM by Gribouillis.)
(Apr-08-2023, 11:57 PM)quazirfan Wrote: Are the parenthesis part of the generator expression?In a sense yes because there is no way to use them without parentheses. However when the generator expression is used as a single argument in a function call, the function call parentheses suffice
func(x is e or x == e for e in y)If there is more than one argument, another pair of parentheses is necessary
func('spam', (x is e or x == e for e in y))List comprehensions are like generator expressions but with square brackets.
[x is e or x == e for e in y]They could also be written with a true generator expression
list(x is e or x == e for e in y)