sorting dictionaries by value

Hilbert hilbert at microsoft.com
Wed Jan 29 09:39:52 CET 2003


Hello,

I have the following dictionary:

>>> dict = {
... "one" : { "red" : 23, "blue" : 99 },
... "two" : { "red" : 43, "blue" : 17 },
... "three" : { "red" : 34, "blue" : 65 },
... "four" : { "red" : 36, "blue" : 38 } }

I'd like to print the value of  "blue" sorted and the corresponding key of
dict, like:

17 "two"
38 "four"
65 "three"
99 "one"

I can't figure out this one.
Any ideas welcome.

Thanks,
Hilbert







More information about the Python-list mailing list