Cannot modify a dict while iterating over it