Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created June 24, 2020 04:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IndhumathyChelliah/3e02107d5146602242c412dd657819a4 to your computer and use it in GitHub Desktop.
Save IndhumathyChelliah/3e02107d5146602242c412dd657819a4 to your computer and use it in GitHub Desktop.
l1=[(1,2,3),(3,1,1),(8,5,3),(3,4,2)]
#Sorted based on second element in the tuple.lambda function returns second element in the tuple
print (sorted(l1,key=lambda x:x[1]))
#Output:[(3, 1, 1), (1, 2, 3), (3, 4, 2), (8, 5, 3)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment