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
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to