[Python-ideas] FW: Map-then-filter in comprehensions

Ethan Furman ethan at stoneleaf.us
Tue Mar 8 12:26:26 EST 2016


On 03/08/2016 06:59 AM, Émanuel Barry wrote:

> The general concept is name binding, so if I see something like
>
> [x for x, y in some_iterable as y > 5]
>
> I’m going be confused by what sort of name binding it does.

I think everyone would be confused because that code is wrong:  it's 
assigning the `iterable` as `y`, and then comparing that to the value `5`.

More realistic (and correct ;) might be:

[z for x, y in some_iterable if x+y as z > 10]

and the result is a list of numbers whose combined value is greater than 10.

A name binding is in fact occuring, so `as` is a fine choice.

--
~Ethan~



More information about the Python-ideas mailing list