Is that one the better (or even more elegant) approach?
stats = {'a':1000, 'b':3000, 'c': 100}
inverse = [(value, key) for key, value in stats.items()]
print max(inverse)[1]
Is that one the better (or even more elegant) approach?
Example:
stats = {'a':1000, 'b':3000, 'c': 100}
if you wanna find the max value with its key, maybe follwing could be simple, without any relevant functions.
max(stats, key=stats.get)
the output is the key which has the max value.
key, value = max(stats.iteritems(), key=lambda x:x[1])
key, _ = max(stats.iteritems(), key=lambda x:x[1])
You can use:
max(d, key = d.get)
# which is equivalent to
max(d, key = lambda k : d.get(k))
To return the key, value pair use:
max(d.items(), key = lambda k : k[1])