Jul-03-2020, 12:23 PM
(This post was last modified: Jul-03-2020, 12:24 PM by Gribouillis.)
Suppose that you want to find the person in a group who owns the most expensive car. In python, you would write it like so
person = max(group, key=price_of_ones_car)Here
group
is an iterable of people, such as a list or a dict which keys are people, and price_of_ones_car
is a function that returns the price of a person's cardef price_of_ones_car(person): return ...Notice that you don't call the function when you call max(). The function will be called for each person by the max function, but you don't need to do it yourself.