OrderedDict.py

evil Japh jeffp at crusoe.net
Fri Apr 9 18:30:04 EDT 1999


Is there a need for a module which allows for ordered processing of an
dictionary?

I have one written, and it works fine I think.  Basically, it allows for a
dictionary to be treated like a list, but have the data structure of
dictionary.  Key-value pairs retain the order you entered them in.  Unless
you specifically change them.  I'm currently working on more methods, to
allow it to be sliced like an array.

currently, it wouldn't allow for numeric keys, because the __getitem__
finds out what you sent, an integer (numeric index) or a string (a
dictionary key).  the __getslice__ and __setslice__ aren't a problem.  I
could make a special class for indices for getting dict[4]...

something like:

dict[Index(4)] instead of dict[4]

but I'd like to be as seamless as possible.

I'll be putting the code on my web site soon.

-- 
Jeff Pinyan (jeffp at crusoe.net)
www.crusoe.net/~jeffp

Crusoe Communications, Inc.
732-728-9800
www.crusoe.net





More information about the Python-list mailing list