Skip to content

Instantly share code, notes, and snippets.

@mym0404
Created May 31, 2022 10:26
Show Gist options
  • Save mym0404/e93b1515de497e46d3e1afd6f9f03dc8 to your computer and use it in GitHub Desktop.
Save mym0404/e93b1515de497e46d3e1afd6f9f03dc8 to your computer and use it in GitHub Desktop.
from functools import cmp_to_key
arr = [1, 2, 3, 4, 5]
def my_cmp(a, b):
if a == b:
return 0
elif a < b:
return -1
else:
return 1
arr.sort(key=cmp_to_key(my_cmp))
for k in arr:
print(k)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment