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

Chris Angelico rosuav at gmail.com
Wed Oct 7 02:01:10 CEST 2015


On Wed, Oct 7, 2015 at 10:21 AM, Sven R. Kunze <srkunze at mail.de> wrote:
> You miss the point. Common use-cases deserve methods on their own. People
> will never stop asking for meaningfully named methods, even when pretending
> comprehensions are the ultimate answer to all questions concerning
> lists/sets/dicts, They simply are not.
>
> Which variant conveys the intent of the developer more clearly?
>
> a.remove_all(1,4,2)
> a[:] = [x for x in a if x not in {1,4,2}]
>

Maybe, but how many other variants do you need? "remove all elements
2.7<x<7.5"? "remove all strings that begin with 'a'"? Every new method
you create adds cognitive load to everyone who reads the docs for the
list object, and every new feature of a method adds cognitive load to
understanding that method. Is it worth it? How common *is* this case?
Is it really worth having the method? Comprehensions already exist,
and are already general enough to handle all the variants.

ChrisA


More information about the Python-ideas mailing list