[Python-ideas] Allow multiple arguments to `list.remove` and flag for silent fail

yoav glazner yoavglazner at gmail.com
Mon Aug 26 23:14:00 CEST 2013


On Aug 27, 2013 12:07 AM, "Sébastien Volle" <sebastien.volle at gmail.com>
wrote:
>
> List comprehension works too:
>
> my_list = [ thing for thing in my_list if thing not in things ]
>
> But both our solutions don't change my_list in place but require creating
a new list, and would not be very practical with big lists.
Your solution will also be slow on large lists.
Since removing an item is o(n)
I would pick a better container or mark items as None instead of removing
them
>
> Anyway, I'd rather stick with the simple for loop than making list
methods too clever.
>
> -- seb
>
> Le 26 août 2013 19:56, <random832 at fastmail.us> a écrit :
>
>> On Mon, Aug 26, 2013, at 13:11, Ram Rachum wrote:
>> > my_list.remove(*things, silent_fail=True)
>> >
>> >
>> > Aside from being much more concise, it could be more efficient too,
>> > couldn't it?
>>
>> my_list = list(filter(lambda x: x in things, my_list))
>> _______________________________________________
>> Python-ideas mailing list
>> Python-ideas at python.org
>> http://mail.python.org/mailman/listinfo/python-ideas
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas

Cheeres
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130827/c0e8fc74/attachment.html>


More information about the Python-ideas mailing list