The min()
function takes a key
argument already, no need for a list comprehension.
Let's say you wanted to find the closest point in the list to the origin:
min(list_of_points, key=lambda p: distance(p, (0, 0)))
would find it (given a distance()
function that calculates the distance between two points).
From the documentation:
The optional key argument specifies a one-argument ordering function like that used for
list.sort()
. The key argument, if supplied, must be in keyword form (for example,min(a,b,c,key=func)
).