sorting values in dict

Don O'Donnell donod at home.com
Fri Jun 15 03:51:39 EDT 2001


Jeroen Wolff wrote:
> 
> I want to display a dict sorted by value.
> 
> This is my dict:
> 
> total={}
...

Use list comprehension to reverse key:value pairs,
then sort the list:

vsort = [(v,k) for k,v in total.items()]
vsort.sort()

-Don



More information about the Python-list mailing list