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 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:
         del the_list[idx]
         num -= 1
     else:
         idx += 1
With a `count` argument to `list.remove`, this is how it would be done:
the_list.remove(element_to_remove, count=num)
(Doesn't necessarily have to be a keyword argument)
Is this a good idea?
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/MMLIWVJEMBTQYTOI3QXJCHV5VYSDEQ66/
Code of Conduct: http://python.org/psf/codeofconduct/

_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/I6G27U5NNXC4QRGE62KJSMTLNZOSQRN5/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to