A video explaining the title a lot better
Be careful! Removing objects from a list shifts all of the items and their indices in it. Doing that while iterating is dangerous for this reason: if you remove object at index i
, then whatever was at index i + 1
is now at i
. But your loop does i++
, skipping it! You must compensate by doing i--
when removing.