can the sequence of entries in a dictionary be depended on?

Carsten Haese carsten.haese at gmail.com
Sun Nov 23 19:59:33 EST 2008


Diez B. Roggisch wrote:
> AFAIK the order is deterministic as long as you don't alter the dict between
> iterations. However, this is an implementation detail.

It's not an implementation detail. It's documented behavior. Thus quoth
http://docs.python.org/library/stdtypes.html#mapping-types-dict :

"""
If items(), keys(), values(), iteritems(), iterkeys(), and itervalues()
are called with no intervening modifications to the dictionary, the
lists will directly correspond.
"""

--
Carsten Haese
http://informixdb.sourceforge.net



More information about the Python-list mailing list