an ordered dictionary

Jeff Pinyan jeffp at
Tue Mar 14 23:27:13 CET 2000

Ordinary (real) dictionaries aren't ordered.  Coming from a Perl
environment, I decided to emulate Tie::IxHash, a module that allows for
ordered (or specified order) hashes (same as dictionaries).

Now, I'm not sure if I should make the keys() OrderedDict method return
the internal list of keys, such that

  od.keys()[1] = 'FOO'

would change a key in the OrderedDict object od.  The internal
representation of an OrderedDict is

  self.KEYS = [ ... ]
  self.hash = { ... }

the hash attribute being a regular dict, and the KEYS attribute being the
list of keys in whatever order they are to be in.  I've been thinking of
changing it, so that values() could be messed with, too, but I don't think
that will be needed, since values can be accessed via index as well as

If anyone's interested, the source is online at

MIDN 4/C PINYAN, NROTCURPI, US Naval Reserve             japhy at        
PerlMonth - An Online Perl Magazine  
The Perl Archive - Articles, Forums, etc.

More information about the Python-list mailing list