sorting values in dict
victor at prodigy.net
Thu Jun 14 23:36:58 CEST 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:
This should produce:
On Thu, 14 Jun 2001 23:24:11 +0200, Jeroen Wolff <jwolff at knoware.nl>
>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...
> 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