When typing the title of my question, Stack Overflow provided a link to this question whose title does admittedly match my question almost exactly:
Calling `.remove()` inside `for` loop doesn't remove all elements
However, that question is about jQuery, which I'd never even heard of before, and the sample code seems to be a lot more complicated than mine. Furthermore, the accepted answer to that question seems to be saying that the code sweeps through the list multiple times and crashes the last time; I don't think that's the case for my example.
def f(x):
for num in x:
if num==np.NINF:
x.remove(num)
return x
print(f([0,np.NINF,np.NINF]))
This returns [0, -inf] instead of the expected [0]. Why?