
On Wed, Dec 22, 2021 at 11:12 AM Jeremiah Vivian <nohackingofkrowten@gmail.com> 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?
If you're removing multiple, it's usually best to filter. This is a great opportunity to learn about list comprehensions and the difference between O(n) and O(n²) :) ChrisA