sorting a dictionary
aleax at aleax.it
Tue Feb 4 10:27:19 CET 2003
[about getting the largest key -- the "sorting" in the subject
is a bit of involuntary misdirection by the OP...:-)]
> def get_highest(d): # don't use the name 'dict'
> l = d.keys()
> return l[-1]
This is good, but it's O(N logN) -- if the dictionary is
huge, you'll be hurting. max(d) is faster, and follows
the good rule of not reimplementing something that Python
already has as a built-in.
More information about the Python-list