[Python-ideas] Add a `count` argument to `list.remove`

2021-12-21 Thread Jeremiah Vivian
I expect some sort of "there's no benefit in this, just write the current implementation", indirectly or directly. Currently, this is the way to remove `num` occurrences of an element from a list: > idx = 0 > while idx < len(the_list) and num: > if the_list[idx] == element_to_remove: >

[Python-ideas] Re: Add a `count` argument to `list.remove`

2021-12-21 Thread Chris Angelico
On Wed, Dec 22, 2021 at 11:12 AM Jeremiah Vivian wrote: > > I expect some sort of "there's no benefit in this, just write the current > implementation", indirectly or directly. > Currently, this is the way to remove `num` occurrences of an element from a > list: > > idx = 0 > > while idx < len(t

[Python-ideas] Re: Add a `count` argument to `list.remove`

2021-12-21 Thread Rob Cliffe via Python-ideas
Currently list.remove raises ValueError if the element is not in the list. When called with the count argument, should it raise ValueError if there are fewer than `count` occurrences of the element in the list? Best wishes Rob Cliffe On 22/12/2021 00:09, Jeremiah Vivian wrote: I expect some s

[Python-ideas] Re: Add a `count` argument to `list.remove`

2021-12-21 Thread MRAB
On 2021-12-22 01:53, Rob Cliffe via Python-ideas wrote: Currently list.remove raises ValueError if the element is not in the list. When called with the count argument, should it raise ValueError if there are fewer than `count` occurrences of the element in the list? There's str.replace and str.s

[Python-ideas] Re: Add a `count` argument to `list.remove`

2021-12-21 Thread Jeremiah Vivian
> When called with the count argument, should it raise ValueError if there > are fewer than `count` occurrences of the element in the list? No, it shouldn't. It would raise ValueError if the element is not found within the list though. ___ Python-ideas