Almost every tutorial and SO answer on this topic insists that you should never modify a list while iterating over it, but I can’t see why this is such a bad thing if the code is valid. For example:
while len(mylist) > 0:
print mylist.pop()
Am I missing something?
You are not iterating over the list. You are each time checking an atomic condition.
Also:
can be rewritten as:
which can be rewritten as: