Solved
RuntimeError: dictionary changed size during iteration
OP
I'm removing inactive crew members while looping over the dict and get this error.
Comments 4
Log in to join the discussion.
Log in Create accountYou can't add or remove keys while iterating over the same dict. Iterate over a copy of the keys, or build a new dict:
The comprehension version is really clean, going with that.
Changing values while iterating is fine, it's only adding/removing keys that breaks it.
Same applies to lists, except lists don't warn you — they just skip elements silently. Even worse!