Terry Reedy email@example.com writes:
[(y, y) for y in (f(x) for x in some_iterable) if y < 2]
Though I would probably write the reusable generator I might write this as
ygen = (f(x) for x in some_iterable) # or map(f, some_iterable) if f is an existing function ypairs = ((y, y) for y in ygen if y < 2)
There are really two ideas: map f to some_iterable make pairs conditionally.
There should be no shame in putting each in a separate statement.
Indeed. My only point with the above example is that, for those who *are* desperate to have this all as a single readable statement, the existing syntax supports it nicely.
Since the existing syntax already easily supports every case where the proposed syntax would be used, the burden is on those proposing the new syntax to demonstrate benefits significant enough to outweigh the costs of adding bulk to the language.
AFAICT, no convincingly significant benefit has been presented to add syntax for this case.
I give strong emphasis on that fact, that where-clause is only syntactic sugar, suggested for better readability.
Too much sugar = stomach ache ;-).