How to use 'python sort tuples by second element' in Python

Every line of 'python sort tuples by second element' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
54def sort_last(tuples):
55 return sorted(tuples, key=lambda x: x[-1])
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

15def SortTwoLists(primary, secondary):
16 # sort two lists by order of elements of the primary list
17 paired_sorted = sorted(zip(primary, secondary), key=lambda x: x[0])
18 return (map(list, zip(*paired_sorted))) # two lists

Related snippets