You are removing from a list while iterating over it. This is not a good idea.
There are other ways to do what you are trying, one of which is to track the list indices of all items that you want to remove from the list and then remove them outside your for-loop