l = [7, 9, 5, 6, 13, 5, 15, 3]
t = max(l, key=lambda g:g if g%9==1 else 0)
t
is the maximum element of l
, whose remainder of the division by 9 is 1.
In this case, t
equals 7. But this list doesn't have any elements whose remainder of the division by 9 is 1 at all! Why doesn't t
equal 0?
The lambda calculates the key for each value to be 0
, and so with all elements having an equivalent key, the first element is returned.
The lambda is simply used to calculate the value for comparison, it does not convert the value that is returned.