[Python-ideas] Minimal built-ins (+ tiny doc suggestion)

Chris Rebert pyideas at rebertia.com
Sat May 26 00:52:54 CEST 2012


On Fri, May 25, 2012 at 2:09 AM, Steven D'Aprano <steve at pearwood.info> wrote:
> Nick Coghlan wrote:
>> I'd personally agree with filter() moving, but "map(str, seq)" still
>> beats "(str(x) for x in seq)" by a substantial margin for me when it
>> comes to quickly and cleanly encapsulating a common idiom such that it
>> is easier both to read *and* write.
>
> filter(None, seq)
> [obj for obj in seq if obj]
>
> I think the version with filter is *much* better than the second.

And I think filter(bool, seq) beats the first. Exact same length, more
explicit, one less key to press (Shift).
The consistency of using comprehensions all the time has a certain
attraction though.

Cheers,
Chris



More information about the Python-ideas mailing list