如何找到字典中最大值对应的键是哪个?
摘要:我有一个字典如下所示: stats = {'a': 1, 'b': 3000, 'c': 0}
我有一个字典如下所示:
stats = {'a': 1, 'b': 3000, 'c': 0}
key是字符串, value是int值, 我想找到最大值对应的key, 在上例中答案是 ‘b’
回答:
max(stats, key=stats.get)
来源:
https://stackoverflow.com/questions/268272/getting-key-with-maximum-value-in-dictionary
