Python: Sort a dictionary by value
Posted
by the empirical programmer
on Stack Overflow
See other posts from Stack Overflow
or by the empirical programmer
Published on 2009-03-05T00:49:05Z
Indexed on
2010/04/24
20:03 UTC
Read the original article
Hit count: 121
I have a dictionary of values read from 2 fields in a database: a string field and a numeric field. The string field is unique so that is the key of the dictionary.
I can sort on the keys, but how can I sort based on the values?
Note: I have read this post 72899 and probably could change my code to have a list of dictionaries but since I do not really need a list of dictionaries I wanted to know if there a simpler solution.
© Stack Overflow or respective owner