我有一个dictionary
:键是字符串,值是整数.
例:
stats = {'a':1000, 'b':3000, 'c': 100}
Run Code Online (Sandbox Code Playgroud)
我想得到'b'
一个答案,因为它是具有更高价值的关键.
我使用具有反向键值元组的中间列表执行以下操作:
inverse = [(value, key) for key, value in stats.items()]
print max(inverse)[1]
Run Code Online (Sandbox Code Playgroud)
这是一个更好(或更优雅)的方法吗?