Q: how to sort a dictionary by the values ?

Bjorn Pettersen pbjorn at uswest.net
Sat Dec 30 19:37:32 CET 2000


items = [ (y,x) for x,y in mydict.items() ]
items.sort()

-- bjorn

hwan-jo yu wrote:

> 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