2 Comments

The Javascript example with a comparison function could also be transcribed to Python in the same fashion by using the cmp_to_key() function from the functools module (https://docs.python.org/3/library/functools.html#functools.cmp_to_key , also https://stackoverflow.com/questions/5213033/sort-a-list-of-lists-with-a-custom-compare-function).

Expand full comment

Yes, any function can be used as a key, and cmp_to_key is an adapter for this purpose.

Expand full comment