[Python-ideas] Allow filter(items)
Markus Unterwaditzer
markus at unterwaditzer.net
Mon Aug 5 19:32:39 CEST 2013
-0, for reasons already mentioned. While i agree that filter(None, items) is counterintuitive, filter(bool, items) looks very readable to me.
I think modifying the behavior of filter like this will at most trick users into thinking they need to specify the iterable first.
-- Markus (from phone)
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)
>filter(len, items)
>filter(lambda s: s != "", strings)
>
>The signature change may lead you to spell
>
>filter(predicate, items) # correct
>
>as
>
>filter(items, predicate) # wrong
>
>but this is a noisy error. I think the advantage of making the magic
>None
>redundant outweighs this potential pitfall.
>
>_______________________________________________
>Python-ideas mailing list
>Python-ideas at python.org
>http://mail.python.org/mailman/listinfo/python-ideas
More information about the Python-ideas
mailing list