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