How to use a custom comparison function in Python 3?

Use the key keyword and functools.cmp_to_key to transform your comparison function:

sorted(x, key=functools.cmp_to_key(customsort))

Leave a Comment