Key callback function:
Max (List,key=none)
Max (range), Key=lambda x:x > 3) #4
Explanation: key= (False,false,false,false,true,.. )
The first item of the max value in key is 4 true, so return 4
Max (' za ', ' bf ', Key=lambda x:x[0]) #za
Explanation: key= (' z ', ' B '), max (key) = ' z ', corresponding za
Say something useful (using key):
Max ([' Tom ', ' + '), (' Tony ', ')],key=lambda x:x[1])
C=max ([' Tom ', ', '), (' Tony ', ')],key=lambda x:x[1])
Print (c)
Printing results are:
(' Tony ', 17)
Max (list (), Key=lambda s:s[1]) represents traversing the elements in the list, using the 1th item of the element as a comparison, and returning the position index of the maximum value;
e.g. alist=[5,0,1,2,3,7,8]
Min (Enumerate (seq), key= s:s[1]) will return 1, meaning the value of the ALIST[1] item is minimal, that is, 0 is the smallest
Python Basics: Key callback function--max (List,key=none)