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

Ethan Furman ethan at stoneleaf.us
Tue Mar 8 13:32:24 EST 2016


On 03/08/2016 10:27 AM, Chris Angelico wrote:

> Implement that, and people will ask why they can't then unroll that:
>
> def <listcomp>():
>      result = []
>      for x, y in some_iterable:
>          if x+y as z > 10: # SyntaxError
>              result.append(z)
>      return z

Seriously?

def blah():
     result = []
     for x, y in some_iterable:
         z = x + y
         if z > 10:
             result.append(z)
     return result  # not z

That doesn't seem too difficult.  ;)

--
~Ethan~


More information about the Python-ideas mailing list