Sorting a list of tuples by the last last elements of the tuple

This commit is contained in:
rasbt 2014-08-02 22:36:17 -04:00
parent 447f588960
commit 841401ab65

View 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')]