PEP 234: Iterators

Toby Dickenson tdickenson at
Tue May 1 12:35:15 CEST 2001

Guido van Rossum <guido at> wrote:

>Dictionary Iterators

>     This means that we can write
>          for k in dict: ...
>      which is equivalent to, but much faster than

faster at runtime, and less typing too ;-)

>          for k in dict.keys(): ...
>      as long as the restriction on modifications to the dictionary
>      (either by the loop or by another thread) are not violated.

What happens if you do violate this? I assume that damage is limited
to seing elements twice, or skipping some elements and not seeing them
at all.

Toby Dickenson
tdickenson at

More information about the Python-list mailing list