mirror of
https://github.com/rasbt/python_reference.git
synced 2024-11-23 20:11:13 +00:00
Sorting a list of tuples by the last last elements of the tuple
This commit is contained in:
parent
447f588960
commit
841401ab65
10
howtos_as_py_files/sort_list_of_tuples_by_ele.py
Normal file
10
howtos_as_py_files/sort_list_of_tuples_by_ele.py
Normal file
|
@ -0,0 +1,10 @@
|
|||
# Sebastian Raschka 09/02/2014
|
||||
# Sorting a list of tuples by the last last elements of the tuple
|
||||
|
||||
a_list = [(1,3,'c'), (2,3,'a'), (1,2,'b')]
|
||||
|
||||
sorted_list = sorted(a_list, key=lambda e: e[::-1])
|
||||
|
||||
print(sorted_list)
|
||||
|
||||
# prints [(2, 3, 'a'), (1, 2, 'b'), (1, 3, 'c')]
|
Loading…
Reference in New Issue
Block a user