On Mon, Jun 22, 2009 at 8:46 AM, Andrey Popp8mayday@gmail.com wrote:
[(y, y) for x in some_iterable if y < 2 where y = f(x)]
looks more naturally than three suggested variants.
Only if you are already thinking about SQL.
An "as" would be almost as good as a "where", and would better match the way python has evolved so far.
But that still doesn't answer the real question. In isolation, I would see either as a real (if perhaps small and isolated) improvement to readability.
The catch is that the improvement must be dramatic enough to justify the cost -- which is extra complexity to the language as a whole. That isn't a cost you see as easily, because you're thinking about comprehensions; it is instead a small tax paid by people doing regular function calls and if branching and for loops. It isn't a big tax, but it is cumulative, and python has worked hard to minimize it.