-
-
Save IndhumathyChelliah/6cbee4066ac2b1e620c3fce9b0eefc19 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
def sort_key(e): | |
return e[1] | |
l1 = [(1, 2, 3), (2, 1, 3), (11, 4, 2), (9, 1, 3)] | |
# By default,sorted based on first element | |
print(sorted(l1)) | |
# Output:[(1, 2, 3), (2, 1, 3), (9, 1, 3), (11, 4, 2)] | |
# Sorted based on second element,by specifying user defined function sort_key | |
print(sorted(l1, key=sort_key)) | |
# Output:[(2, 1, 3), (9, 1, 3), (1, 2, 3), (11, 4, 2)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment