def my_cmp(x, y):
    return x * 5 - y * 2
l = [50, 2, 1, 9]
print(sorted(l, key=functools.cmp_to_key(my_cmp)))
l = [50, 1, 2, 9]
print(sorted(l, key=functools.cmp_to_key(my_cmp)))
What's the proper way to write comparator as key in Python 3 for sorting?