Skip to content

Instantly share code, notes, and snippets.

@Sangarshanan
Created July 2, 2018 14:45
Show Gist options
  • Save Sangarshanan/9f3d8f3ccc8ceb4bde6ab04c03d62592 to your computer and use it in GitHub Desktop.
Save Sangarshanan/9f3d8f3ccc8ceb4bde6ab04c03d62592 to your computer and use it in GitHub Desktop.
When you wanna sort
10 2 5
7 1 0
9 9 9
1 23 12
6 5 9
with respect to element 1 (2,1,9,23,5)
print(sorted(rows, key=lambda row: int(row.split()[1])))
key => specifies which elemsnt of a list to sort with respect to
7 1 0
10 2 5
6 5 9
9 9 9
1 23 12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment