[Python-ideas] Allow filter(items)

Shane Green shane at umbrellacode.com
Mon Aug 5 14:55:17 CEST 2013


+1.  

Isn’t None’s meaning in this context basically the identity function?  If so, then passing the iterable to filter directly seems to make more sense.


On Aug 5, 2013, at 12: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) 
> 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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130805/4ce74a4b/attachment.html>


More information about the Python-ideas mailing list