Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当有多个具有相同值的键时,如何获取具有最大值的键。示例:d = 'a': 1, 'c': 4, 'b': 99, 'e': 4, 'f': 99},我需要返回'b','f'
>>> d = {'a': 1, 'c': 4, 'b': 99, 'e': 4, 'f': 99} >>> maxval = max(d.values()) >>> [k for k in d if d[k]==maxval] ['b', 'f']
该死的 :P 被打败了一分钟。干杯 m8。
maxValue = max(d.values()) print [key for key in d.keys() if d[key]==maxValue]