Skip to content

Latest commit

 

History

History
26 lines (19 loc) · 466 Bytes

74.md

File metadata and controls

26 lines (19 loc) · 466 Bytes
@author jackzhenguo
@desc 
@date 2019/4/15

74 值最大的字典

def max_pairs(dic):
    if len(dic) == 0:
        return dic
    max_val = max(map(lambda v: v[1], dic.items()))
    return [item for item in dic.items() if item[1] == max_val]

测试举例:

r = max_pairs({'a': -10, 'b': 5, 'c': 3, 'd': 5})
print(r)  # [('b', 5), ('d', 5)]
[上一个例子](73.md) [下一个例子](75.md)