001、 输出键最大的项
a、
>>> dict1 = {"c":30, "a":40, "b":80, "d":20, "e":60} >>> dict1 {'c': 30, 'a': 40, 'b': 80, 'd': 20, 'e': 60} >>> max_key = max(dict1.keys()) >>> max_key 'e' >>> print(max_key, dict1[max_key]) ## 输出键最大的项 e 60
b、输出键最大的项
>>> dict1 = {"c":30, "a":40, "b":80, "d":20, "e":60} >>> dict1 {'c': 30, 'a': 40, 'b': 80, 'd': 20, 'e': 60} >>> max(dict1.items(), key = lambda x:x[0]) ## 输出键最大的项 ('e', 60)
002、输出键最小的项
a、
>>> dict1 = {"c":30, "a":40, "b":80, "d":20, "e":60} >>> dict1 {'c': 30, 'a': 40, 'b': 80, 'd': 20, 'e': 60} >>> min_key = min(dict1.keys()) >>> min_key 'a' >>> print(min_key, dict1[min_key]) ## 输出键最小的项 a 40
b、 输出键最小的项
>>> dict1 = {"c":30, "a":40, "b":80, "d":20, "e":60} >>> dict1 {'c': 30, 'a': 40, 'b': 80, 'd': 20, 'e': 60} >>> min(dict1.items(), key = lambda x:x[0]) ## 输出键最小的项 ('a', 40)
。
标签:输出,dict1,python,30,最小,40,60,key,20 From: https://www.cnblogs.com/liujiaxin2018/p/17663383.html