[Python-ideas] Allow filter(items)

Shane Green shane at umbrellacode.com
Wed Aug 7 11:07:50 CEST 2013


Okay, that makes sense.  Sadly I think typed it that mostly out of habit; sometimes I fallback to when keyword arguments were a bit more exceptional than they are today.  That would probably be the best way to accept an explicit predicate, don’t you think?  

You make a good point, even though I’m all for filter(items), invoking items.filter() with no arguments work as well because you don’t have as obvious of a connection between identity(items) being replaced by items like there is in the other case.  Then again, when you invoke an in-place filter in a collection of items without any arguments, what else would you expect it to drop but drop its falsy entries?

I’m undecided on predicate as keyword vs. required param; agree default predicate=None is a bad choice.  


On Aug 7, 2013, at 1:43 AM, Stephen J. Turnbull <stephen at xemacs.org> wrote:

> Shane Green writes:
> 
>> we should consider adding an in-place “filter(predicate=None)”
>> method to list
> 
> -1 on the default.
> 
> One of the things I like about Python is that it mostly manages to
> eschew magic values (like "None" meaning "bool") and spurious brevity
> (like defaulting the predicate).  While "bool" may be the most common
> predicate here, it's not obvious to me what the absence of the
> predicate means.  On both counts, I'm against this (or any) default.
> 
> Specifically, in most of the applications where I personally would
> want to use something like "filter", zeros and empty lists are typically
> valid values.  So I'd want to filter "None" or similar "not available"
> values.  Therefore I would expect "is not None" to be the default.
> 
> Steve

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130807/9585d4a5/attachment.html>


More information about the Python-ideas mailing list