取字典中最大最小值对应的键
# 取最大值对应的键
tmp_dict = {"a": 1,
"b": 3,
"c": 9,
"d": 13}
max_key = max(tmp_dict, key=lambda x: tmp_dict[x])
print(f"max key: {max_key}")
# 取对小值对应的键
tmp_dict = {"a": 1,
"b": 3,
"c": 9,
"d": 13}
min_key = min(tmp_dict, key=lambda x: tmp_dict[x])
print(f"min key: {min_key}")
标签:tmp,min,max,最小值,dict,key,对应,字典
From: https://www.cnblogs.com/bonne-chance/p/17564746.html