sorting values in dict

Jeroen Wolff jwolff at knoware.nl
Thu Jun 14 17:24:11 EDT 2001


I want to display a dict sorted by value.

This is my dict:

total={}
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)
else:
    total[srcAS] = string.atoi(Bytes)


This is how i sort it by keys:

keys = total.keys()
keys.sort()
for n in keys:
    print n, total[n]


But i would like to have is sorted (on screen) by value....

Is this possible?

Jeroen



More information about the Python-list mailing list