取字典中最大最小值对应的键
取字典中最大最小值对应的键
# 取最大值对应的键
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}")