[Python-ideas] Allow filter(items)

Shane Green shane at umbrellacode.com
Wed Aug 7 05:29:06 CEST 2013


I knew when I wrote the first email that I shouldn’t have deleted (aside from being terribly inefficient) from what I wrote :-)  

My point is that these are implementation details: as a newcomer who saw a sorted function, would it make sense to expect a filtered one; and as a newcomer who saw list.sort, would it make sense to expect list.filter?  
Because I don’t think it necessarily follows that a newcomer who noticed lists have a filter method meant that filter method was the most efficient approach to filtering.



On Aug 6, 2013, at 8:09 PM, Andrew Barnert <abarnert at yahoo.com> wrote:

> On Aug 6, 2013, at 19:52, Joshua Landau <joshua at landau.ws> wrote:
> 
>>> (and why not have a list.filter(predicate=None) to perform in place
>>> filtering for that matter?)
>> 
>> sorted actually just converts to a list and then runs the sort method
>> AFAICT. sort is defined in-place because it's efficient that way. None
>> of this applies to filter.
> 
> A lot of newcomers from C-like languages expect in-place filtering to be more efficient, and put a whole lot of effort into writing complex and buggy code that avoids all the linear del a[i] calls before finally testing and seeing that a[:] = filter() is still faster in almost every case. Maybe the docs should actually explain (where? no idea...) that filtering in-place isn't more efficient, and that's why there's no filter method and filtered function?
> _______________________________________________
> 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/20130806/1556f9fb/attachment-0001.html>


More information about the Python-ideas mailing list