1

取字典中最大最小值对应的键

取字典中最大最小值对应的键

# 取最大值对应的键
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}")
posted @ 2023-07-19 09:43  Bonne_chance  阅读(27)  评论(0编辑  收藏  举报
1