how to sort a dictionary by the values ?

Jason Cunliffe jasonic at
Sat Dec 30 19:44:35 CET 2000

Depending upon your needs, check out Wolfgang Grafen's wonderful SEQDICT


seqdict - single value dictionary
msedict - multiple value dictionary

The Python built-in dictionary has no reliable sequence order because of
performance reasons.

The two new dictionaries introduced here keep their entries in sequence.

* seqdict keeps one value for one key
* mseqdict keeps multiple values per key and is the closest emulation of
areal world dictionary.

As the sequential dictionary is a combination of a list and a dictionary you
can do most operations defined with lists as well and much more.
Now you can slice, add, sort with dictionaries. The functional operations
map, filter, reduce are implemented as well. Use a dictionary like a stack
with push and pop. Split it, reverse it and swap keys and values.
A small tutorial is provided as HTML and Postscript Source and is subject to
become improved some other day.
I think both dictionaries are candidates for the python standard library.
Use the seqdicts to emulate a printed dictionary. Use them for workinse them
for working with csv-tables. Keep parsed code in a seqdict, modify it and
write it back ...

have fun..
- Jason
Jason CUNLIFFE = NOMADICS['Interactive Art and Technology']
hwan-jo yu <hwanjoyu at> wrote in message
news:Pine.GSO.4.10.10012292313350.21787-100000 at
> Hi,
> If I sort the items() of dictionary, it is sorted by first the key and
> second the value.
> How can I sort it by the values ?
> Thanks in advance.

More information about the Python-list mailing list