OrderedDict.py

Neil Hodgson neilh at fast.fujitsu.com.au
Mon Apr 12 05:11:18 EDT 1999


evil Japh (or possibly his good twin Jeff Pinyan) wrote:

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

    I think there is a need for this. There is a bit of code I wrote for
PythonWin where some values are displayed in a UI and then read back in
after user modification. It did not matter what order the dictionary was
displayed in so long as it could be read back in in the same order to
match up. Nothing in the documentation specifies that asking for the
elements (or keys) of a dictionary returns elements (or keys) in the
same order each time, even if no modifications are done to the
dictionary between accesses. Therefore, each time the dictionary was
used, there was a sequence like: 

    sortedkeys = formats.keys()
    sortedkeys.sort()
    for f in sortedkeys:

    Your module may have made this code easier and also clearer.
 
    Neil Hodgson
    Fujitsu Australia Software Technology




More information about the Python-list mailing list