diff --git a/howtos_as_py_files/sort_list_of_tuples_by_ele.py b/howtos_as_py_files/sort_list_of_tuples_by_ele.py new file mode 100644 index 0000000..972d35d --- /dev/null +++ b/howtos_as_py_files/sort_list_of_tuples_by_ele.py @@ -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')] \ No newline at end of file