Iterating order of dict.items()

Terry Reedy tjreedy at udel.edu
Tue Jul 22 18:11:02 EDT 2003


"Robin Cull" <robin.cull at pace.co.uk> wrote in message
news:16469f07.0307220706.5e2fe1e4 at posting.google.com...
> The order the items comes out in appears to be undefined.

Correct.

> I would have thought that without any other sorting that the items
> would just come out in the order that the dict was defined in,

No, the whole point of hashing keys is to pseudorandomly spread them
more or less uniformly around the storage array with as little
dependence on input order as possible.  This is what make insertion
and deletion close to O(1) rather than O(n) operations.

Terry J. Reedy






More information about the Python-list mailing list