### man和mix的高级使用 age_dic={'xiaoma':18,'zhangfei':20,'xiaowang':36,'lihao':13,} print(max(age_dic.values())) 结果: 36 print(max(age_dic)) # 对比ASCII码 结果: zhangfei # #需求:默认比较的是字典的Key age_dic={'xiaoma':18,'zhangfei':20,'xiaowang':36,'lihao':13,} t = zip(age_dic.values(),age_dic.keys()) print(max(list(t))) 结果: (36, 'xiaowang') print(list(max(zip(age_dic.values(),age_dic.keys())))) 结果: [36, 'xiaowang']
终极版:
## 终极版 age_dic=[{'name':'xiaoma','age':18}, {'name':'zhangfei','age':20}, {'name':'xiaowang','age':36}, {'name':'lihao','age':13}, ] print('年纪最大的:',max(age_dic,key=lambda n:n['age'])) 年纪最大的: {'name': 'xiaowang', 'age': 36}