From 841401ab65a23d77c86b8126dc28d5deb6c141b1 Mon Sep 17 00:00:00 2001 From: rasbt Date: Sat, 2 Aug 2014 22:36:17 -0400 Subject: [PATCH] Sorting a list of tuples by the last last elements of the tuple --- howtos_as_py_files/sort_list_of_tuples_by_ele.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 howtos_as_py_files/sort_list_of_tuples_by_ele.py 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