Iterating order of dict.items()

Jp Calderone exarkun at intarweb.us
Tue Jul 22 12:03:17 EDT 2003


On Tue, Jul 22, 2003 at 08:06:28AM -0700, Robin Cull wrote:
> [snip]
> 
> So, is the order of dict.items() defined?  If so, what is that order? 
> Is there any way to control the order my dict is iterated over?

   The order is implementation dependent.  It may change across different
versions of Python, and should not be depended upon.  There is no way to
control this in the built-in dictionary type, but it is possible to subclass
dict and override any of keys/values/items/iterkeys/itervalues/iteritems you
desire to acheive the appropriate ordering.

  Jp

-- 
"One World, one Web, one Program." - Microsoft(R) promotional ad
"Ein Volk, ein Reich, ein Fuhrer." - Adolf Hitler





More information about the Python-list mailing list