[Python-ideas] Allow filter(items)
Andrew Barnert
abarnert at yahoo.com
Wed Aug 7 05:09:27 CEST 2013
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?
More information about the Python-ideas
mailing list