sorting values in dict

Victor Muslin victor at
Thu Jun 14 17:36:58 EDT 2001

This may not be the shortest or most efficient, but it does the trick:

for k,v in a.items():
for v,k in l:
  print v,k

This should produce:

7 c
8 b
9 a

On Thu, 14 Jun 2001 23:24:11 +0200, Jeroen Wolff <jwolff at>

>I want to display a dict sorted by value.
>This is my dict:
>srcAS = a string which i wil take from a file....
>Bytes  = also a string which i wil take from a file...
>if total.has_key(srcAS):
>    total[srcAS] = total[srcAS] + string.atoi(Bytes)
>    total[srcAS] = string.atoi(Bytes)
>This is how i sort it by keys:
>keys = total.keys()
>for n in keys:
>    print n, total[n]
>But i would like to have is sorted (on screen) by value....
>Is this possible?

More information about the Python-list mailing list