sorting values in dict

Florian Scholz feedback at netlcr.de
Thu Jun 14 18:41:38 EDT 2001


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

--------another code-snip---
def swap(el):
  return (el[1],el[0]);

total = {}
list = map(swap,total.items());
list.sort();

------  or shorter ------
total = {}
list = map(lambda el : (el[1],el[0])    ,total.items());
list.sort();






More information about the Python-list mailing list