1my_list = [9, 3, 1, 5, 88, 22, 99]
2
3# sort in decreasing order
4my_list = sorted(my_list, reverse=True)
5print(my_list)
6
7# sort in increasing order
8my_list = sorted(my_list, reverse=False)
9print(my_list)
10
11# another way to sort using built-in methods
12my_list.sort(reverse=True)
13print(my_list)
14
15# sort again using slice indexes
16print(my_list[::-1])
17
18# Output
19# [99, 88, 22, 9, 5, 3, 1]
20# [1, 3, 5, 9, 22, 88, 99]
21# [99, 88, 22, 9, 5, 3, 1]
22# [1, 3, 5, 9, 22, 88, 99]
1numbers = [1, 5, -2, 4]
2# Sort in ascending order, applied in place
3numbers.sort()
4# Sort in descending order, applied in place
5numbers.sort(descending=True)
1nums = [48, 35, 32, 5, 5, 16, 5, 16, 28, 29] # Makes a list of numbers
2
3sortedNums = sorted(nums, key=int) # Sorts the numbers and saves it as a variable
4print(sortedNums) # Prints the variable
1# sort() will change the original list into a sorted list
2vowels = ['e', 'a', 'u', 'o', 'i']
3vowels.sort()
4# Output:
5# ['a', 'e', 'i', 'o', 'u']
6
7# sorted() will sort the list and return it while keeping the original
8sortedVowels = sorted(vowels)
9# Output:
10# ['a', 'e', 'i', 'o', 'u']