(抱歉标题模糊)
dic = {1:20, 2:20, 3:20, 4:10}
我希望它返回 3,因为这是字典中三个重复值之间的最大键编号。
我目前拥有的是:
return max(dic, key = dic.get)
但这不会得到我想要的结果,会返回 1
最佳答案
最大化(值,键)对:
k, _ = max(dic.items(), key=lambda item: item[::-1])
dict 项是元组,元组是有序的lexicographically .
https://stackoverflow.com/questions/67512210/