Advanced use of max and min

age={ ' tom ' :18, ' cat ' :19, ' jerry ' :30, ' dog ' :12 }
 # print(max(age.values())) 
# print(min(age.values()) ) 
# print(max(age))#The dictionary compares the key by default 
# for i in zip(age.values(),age.keys()): 
#      print(i)

print (list(min(zip(age.values(),age.keys())))) # zip realizes the exchange of value and key 
 # Different types cannot be compared
people=[
{'name':'cat','age':14},
    {'name':'dog','age':88},
    {'name': 'tom', 'age': 33},
]
print ( ' take out ' ,max(people,key= lambda dic:dic[ ' age ' ])) # take out the maximum value 
print ( ' take out ' ,min(people,key= lambda dic:dic[ ' age ' ]))

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325040336&siteId=291194637