You stumbled upon the difference in the implementation of .sort and max more than the problem with the language.
list.sort() takes a key argument of "key", which defaults to "None". This means that the sorting method cannot determine the difference between the delivery of the key=None argument or just the default value. In any case, it behaves as if no key function was provided.
max , on the other hand, checks for the presence of the keyword "key". It does not have a default value, and its value is used as a key function, if present at all.
In any case, the key should never be delivered as None. This is supposed to be a function that is used to extract the "key" value from the items in the / iterable list. For example:
a = [("one", 1), ("two", 2), ("three", 3), ("four", 4)] a.sort(key=lambda item:item[1])
David K. Hess
source share