How is max supposed to work, especially key.

Steven D'Aprano steve+comp.lang.python at pearwood.info
Thu Dec 4 07:03:05 EST 2014


Albert van der Horst wrote:

> I agree that it is a useful function and that it is doing
> the right thing. What is wrong is the name.
> I refer to the fact that it is not returning the maximum.
> It returns the iterator value that leads to the maximum.

That is incorrect. It returns the maximum value, that is, the value greater
than all the other values. What is different is the way "this value is
greater than that value" is tested for the purposes of calculating this
maximum.

> A function that doesn't return a maximum shouldn't be called
> maximum.

Naturally. But this does calculate the maximum, according to the given key
function.


-- 
Steven




More information about the Python-list mailing list