[Python-ideas] Allow multiple arguments to `list.remove` and flag for silent fail
Peter Otten
__peter__ at web.de
Mon Aug 26 20:02:44 CEST 2013
Ram Rachum wrote:
> Why do I have to do this:
>
> for thing in things:
> try:
> my_list.remove(thing)
> except ValueError:
> pass
>
>
> When I could do this:
>
> my_list.remove(*things, silent_fail=True)
>
>
> Aside from being much more concise, it could be more efficient too,
> couldn't it?
Have you considered a set instead of a list?
my_set.difference_update(things)
is certainly more efficient if the items in the list are hashable, occur
only once, and you don't care about order.
More information about the Python-ideas
mailing list