Created
August 10, 2017 01:30
-
-
Save harrifeng/e2dc1182d89f4eef06a12a91b54ae8c9 to your computer and use it in GitHub Desktop.
This file contains 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
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