While initially creating a kind of queue for something else I encountered a weird "problem": If I iterate over the queue and would remove every element via the list.remove(x)
command I expect the empty list to be the result. But it doesn't, instead in returns basically a sublist as far as I can see.
test = ['1', '4', '3', '5']
for entry in test:
test.remove(entry)
print(test) # Prints ['4', '5']
The official documentation for list.remove(x)
states:
Remove the first item from the list whose value is x. It is an error if there is no such item.
I tried it with other examples (i.e. '1', '4', '3' prints '4' or '1', '2', '3' prints '2') but the "error" occurs every time. Am I missing something obvious? Or is the command supposed to be used in another way?