Python – Getting key with maximum value in dictionary


I have a dictionary: keys are strings, values are integers.


stats = {'a':1000, 'b':3000, 'c': 100}

I'd like to get 'b' as an answer, since it's the key with a higher value.

I did the following, using an intermediate list with reversed key-value tuples:

inverse = [(value, key) for key, value in stats.items()]
print max(inverse)[1]

Is that one the better (or even more elegant) approach?

Best Solution

max(stats, key=stats.get)