Skip to content

Instantly share code, notes, and snippets.

@harrifeng
Created August 10, 2017 01:30
Show Gist options
  • Save harrifeng/e2dc1182d89f4eef06a12a91b54ae8c9 to your computer and use it in GitHub Desktop.
Save harrifeng/e2dc1182d89f4eef06a12a91b54ae8c9 to your computer and use it in GitHub Desktop.
a = [1, 2, 3, 4]
b = [2, 3, 2, 5]
print(a, b)
#########################################
# key is a function that uses one paras #
#########################################
print(sorted([a, b], key=lambda x: x[2]))
def mycmp(x, y):
return x[2] - y[2]
#########################################
# cmd is a function that uses two paras #
#########################################
print(sorted([a, b], cmp=mycmp))
# <===================OUTPUT===================>
# ([1, 2, 3, 4], [2, 3, 2, 5])
# [[2, 3, 2, 5], [1, 2, 3, 4]]
# [[2, 3, 2, 5], [1, 2, 3, 4]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment