Python Basics: Key callback function--max (List,key=none)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.