I am a bit puzzled by the behavior of the key argument in min() and max()
Let's say I have the following list: c=[10,11,15,25,50]
I want the max value above 20, so I do: max(c,key= lambda x: x>20)
. Result is 25, should be 50.
I want the max value below 20, so I do: max(c,key= lambda x: x<20)
. Result is 10, should be 15.
Same thing with min(). If I want the min values above 20 (min(c,key= lambda x: x>20)
), this will give me 10, instead of 25.
Can someone please help explain? I would like to understand better in order to avoid mistakes when dealing with different conditions.