nDimensional sparse histogram in python.
Kirk McDonald
mooquack at suad.org
Wed Feb 1 23:18:57 EST 2006
KraftDiner wrote:
> Many thanks everyone.
>
> One last quick question...
> The dictionary, I believe, is sorted by the key.
> Is there a way to sort it by the value?
> Say I wanted to put out a list of the frequency sorted by highest to
> lowest?
>
The dictionary itself is actually unordered; a C++ std::map this ain't.
To sort its elements, you need to build a list of the items and sort
that, e.g.:
items = [(v, k) for k, v in self.histo.items()]
items.sort()
This will give you a list of (value, key) tuples sorted by value.
-Kirk McDonald
More information about the Python-list
mailing list