Created
May 31, 2022 10:26
-
-
Save mym0404/e93b1515de497e46d3e1afd6f9f03dc8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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