how to sort a dictionary by the values ?

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


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

http://home.germany.net/100-366919/Python/Modules/Modules.html

<quote>

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 ...
</quote>

have fun..
- Jason
___________________________________________________________
Jason CUNLIFFE = NOMADICS['Interactive Art and Technology']
hwan-jo yu <hwanjoyu at students.uiuc.edu> wrote in message
news:Pine.GSO.4.10.10012292313350.21787-100000 at ux11.cso.uiuc.edu...
> 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