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

Terry Reedy tjreedy at udel.edu
Mon Oct 5 22:18:46 CEST 2015


On 10/5/2015 2:28 AM, Sven R. Kunze wrote:
> On 04.10.2015 01:32, Andrew Barnert via Python-ideas wrote:
>> And now, everywhere you use it looks like this:
>>
>>      remove_all(arr, 1)
>>
>> And it's hard to imagine anything more readable.
>
> arr.remove_all(1)
>
>> And, even if remove_all isn't the kind of function an experienced
>> developer would write, learning how to factor out the tricky bits into
>> documentable and testable functions is one of the most useful skills
>> for any developer in any language.#
>
> True.
>
>
> Btw. the same is true for Python core devs. This said, I would
> appreciate the method 'remove_all' provided by the stdlib. ;-)

The problem with methods is that they only work with one class.  A 
list.removeall would only remove things equal to a specific item from a 
list (and presumably in place).  We already have both a generic filter 
function and syntax that will remove all items from any iterable that 
meet any condition.  The stream can be fed into any other function that 
accept an iterable.

-- 
Terry Jan Reedy



More information about the Python-ideas mailing list