sorting a dictionary

dsavitsk dsavitsk at e-coli.net
Tue Feb 4 03:03:07 EST 2003


def get_highest(d): # don't use the name 'dict'
    l = d.keys()
    l.sort()
    return l[-1]

-d

"Yuval" <yuvalfeld at hotmail.com> wrote in message
news:6ca96053.0302032256.63f147be at posting.google.com...
> I'm looking for an efficient way to get the key of the highest value
> in a dictionary.
> For example, for dict = {"a":10, "b":5, "c":15}, I want to write a
> function get_highest(dict), that will return c as the result (since c
> is the key of the highest value in the dict.
>
> Thanks.






More information about the Python-list mailing list