Python Learning notes-the best built-in functions Max and Min

Source: Internet
Author: User
Tags iterable

This article mainly introduces the operation mechanism of Max, and how to pass in and compare, the Min function is the same as Max, but Min takes the minimum value.

The maximum/minimum value of this sequence is returned directly following the max/min sequence.

Max (iterable, key, default) asks for the maximum value of the iterator, where iterable is the iterator, and Max will be for ... Iterate over the iterator and then pass each return value of the iterator as a parameter to the Func in Key=func (typically defined with a lambda expression), then pass the Func execution result to key and then size the key as a standard.

The following returns the maximum value according to the different judging criteria also different

D1 = {'name':'Egon',' Price': 100}d2= {'name':'RDW',' Price': 666}d3= {'name':'Zat',' Price': 1}L1=[D1, D2, D3]a= Max (L1, key=Lambdax:x['name'])Print(a) b= Max (L1, key=Lambdax:x[' Price'])Print(b)

Execution results

{'name'zat' Price': 1} {  'name''rdw ' Price ': 666}

Python Learning notes-the best built-in functions Max and Min

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.