[Python-ideas] Allow filter(items)

Chris Angelico rosuav at gmail.com
Tue Aug 6 08:53:50 CEST 2013


On Mon, Aug 5, 2013 at 8:46 AM, Peter Otten <__peter__ at web.de> wrote:
> filter(items)
>
> looks much cleaner than
>
> filter(None, items)
>
> and is easy to understand. Fewer people would use alternative spellings like
>
> filter(bool, items)

As an alternative (and simpler) to the proposal currently on the
table: Would it improve clarity if the magic of None were instead
applied to 'bool'? The third spelling here would thus be blessed with
a usage recommendation and possible performance improvement
(eliminating a redundant call, but only if the arg 'is bool'), while
still having most of the readability that the one-arg form aims for.
(Obviously backward compat will mean that None will continue to have
its magic, but it would be the less-recommended option. New code would
be encouraged to use filter(bool,...) which would have the exact same
effect.)

ChrisA


More information about the Python-ideas mailing list