[Python-ideas] Proposal how to remove all occurrences of a value from a Python list

Chris Angelico rosuav at gmail.com
Wed Oct 7 00:50:15 CEST 2015


On Wed, Oct 7, 2015 at 3:29 AM, Sven R. Kunze <srkunze at mail.de> wrote:
> Btw. one could also think of an additional generalization for this that
> basically takes n arguments which are then removed altogether from the list
> in question:
>
> a = [1,2,3,5,4,2,3,4,1,2]
> a.remove_all(1,4,2)
> a == [3,5,3]
>
> Just thinking, and I might remember some time where I would have found it
> useful. Not sure.
>

The more generalizations you offer, the more tempting the
comprehension looks. It already allows as many generalizations as you
like, because comprehensions are a fully-supported part of the
language.

ChrisA


More information about the Python-ideas mailing list