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

Koos Zevenhoven k7hoven at gmail.com
Thu Mar 10 08:11:25 EST 2016


On Wed, Mar 9, 2016 at 12:10 AM, Mark Mollineaux
<bufordsharkley at gmail.com> wrote:
[...]

> Also, Koos's offering above:
>
>> [abs(x) for x in numbers if > 5]
>
> Is also very nice, but I don't like it when the filtering is:
>
> [abs(x) for x in numbers if]
>

I assume you mean filter out zeros?

Then it could be

[abs(x) for x in numbers if != 0]

Or someone might want to do

[foo(x) for x in things if not None]


Another possibility might be

[abs(x) if > 5 for x in numbers]

[foo(x) if not None for x in things]


 -- Koos


More information about the Python-ideas mailing list