From 442e642115de1ae3c0ac2688b2f4b8f8e542c812 Mon Sep 17 00:00:00 2001 From: PRADYUMNA BISWAL <40159030+Pradyumnabiswal99@users.noreply.github.com> Date: Tue, 26 Oct 2021 09:23:11 +0530 Subject: [PATCH] Create List_sort_methods.py list sort methods of different type in pyhton. --- Sorting/List_sort_methods.py | 53 ++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 Sorting/List_sort_methods.py diff --git a/Sorting/List_sort_methods.py b/Sorting/List_sort_methods.py new file mode 100644 index 0000000..05cbe27 --- /dev/null +++ b/Sorting/List_sort_methods.py @@ -0,0 +1,53 @@ +numbers = [1, 3, 4, 2] + +# Sorting list of Integers in ascending +numbers.sort() + +print(numbers) + +#____________________________________________ + +strs = ["geeks", "code", "ide", "practice"] + +# Sorting list of Integers in ascending +strs.sort() + +print(strs) + +#______________________________________________ + +numbers = [1, 3, 4, 2] + +# Sorting list of Integers in descending +numbers.sort(reverse = True) + +print(numbers) + +#______________________________________________ + +# Python program to demonstrate sorting by user's +# choice + +# function to return the second element of the +# two elements passed as the parameter +def sortSecond(val): + return val[1] + +# list1 to demonstrate the use of sorting +# using using second key +list1 = [(1, 2), (3, 3), (1, 1)] + +# sorts the array in ascending according to +# second element +list1.sort(key = sortSecond) +print(list1) + +# sorts the array in descending according to +# second element +list1.sort(key = sortSecond, reverse = True) +print(list1) + +#____________________________________________ + + +