Modifying a list while iterating over it