您可以通过这种方式一次性完成。
第一个元素:
>>> dictionary = {"first": [30, 40], "second": [10, 30], "third": [20, 50] }
>>> sorted(dictionary, key=lambda key: dictionary[key][0], reverse=True)
['first', 'third', 'second']
然后使用排序列表的索引来返回有问题的元素:
>>> sorted(dictionary, key=lambda key: dictionary[key][0], reverse=True)[0]
'first'
第二个要素:
>>> sorted(dictionary, key=lambda key: dictionary[key][1], reverse=True)
['third', 'first', 'second']
如果您希望第二个元素与第一个元素打破平局:
>>> dictionary = {"first": [30, 40], "second": [10, 30], "third": [20, 50],
... "fourth":[30,60]}
>>> sorted(dictionary, key=lambda key: dictionary[key][0:2], reverse=True)
['fourth', 'first', 'third', 'second']