looping through the keys of a dictionary

Courageous jkraska1 at san.rr.com
Wed Aug 22 14:16:46 EDT 2001


> None of those create a list.  OTOH, if you try to *mutate* the dict while
> iterating over it in these ways, you deserve whatever you get.

I recommend fail-fast iterators: the dictionary object itself keeps
track of its active iterators and invalidates them if it's mutated.
Subsequent attempts to iterate on the invalidated iterator result
in a ConcurrentModificationException.


C//







More information about the Python-list mailing list