List iteration and remove() call.

Python will modify the list in-place. This means that when the remove() call is performed, a new list is created, without the removed data. Since the list is being iterated over, the 'next' element is now at the same index of the one just removed...which is now skipped over.

Instead of modifying the list being iterated over, make a new list and append only what is needed. This also has the benefit of not copying the list every time something needs removed.