Order of tuples in dict.items()
Paul Hankin
paul.hankin at gmail.com
Sun Oct 14 10:41:52 EDT 2007
On Oct 14, 3:28 pm, Will McGugan <w... at willNOmcguganSPAM.com> wrote:
> If I have two dictionaries containing identical values, can I be sure
> that the items() method will return tuples in the same order?
> ...
> Can I rely on this behavior?
No. To quote the python documentation:
> Keys and values are listed in an arbitrary order which is
> non-random, varies across Python implementations, and
> depends on the dictionary's history of insertions and deletions.
In general, looking at documentation is better than experimenting when
you want to know if something is either always true or mostly true.
--
Paul Hankin
More information about the Python-list
mailing list