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

Koos Zevenhoven k7hoven at gmail.com
Fri Mar 11 14:59:16 EST 2016


On Fri, Mar 11, 2016 at 2:42 PM, João Bernardo <jbvsmo at gmail.com> wrote:
>
> On Thu, Mar 10, 2016 at 7:20 PM, Michał Żukowski <thektulu.pp at gmail.com>
> wrote:
>>
[...]
>> (x+y)**2 + (x-y)**2 where x=1, y=2
>>
>> So for list comprehension I can write:
>>
>> [stripped for line in lines if stripped where stripped=line.strip()]
>
> Why are we not funding this?
> But seriously, why? This is great.
>

One cool thing about this 'where' thing is that, if it made a new
scope on every iteration, you could do

[lambda x: x * j for i in range(10) where j = i]

and it would actually create ten *different* functions (as opposed to
without the 'where j = i').

 - Koos


More information about the Python-ideas mailing list