The Python functools.cmp_to_key utility converts a sorting comparison function (e.g. Python 2, JavaScript) into a sorting key.
It works is by returning a custom object whose sorting protocol methods are defined in terms of the comparison function.
github.com/python/cpython/bl…