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]
1thislist = ["orange", "mango", "kiwi", "pineapple", "banana"]
2thislist.sort()
3print(thislist)
1Numbers = []
2iterate = 0
3
4while len(Numbers)<5:
5 try:
6 x = int(input("Insert the number you want in the list: "))
7 Numbers.append(x)
8 except:
9 print("The input MUST be a number.")
10 continue
11 for iteration_count in range(len(Numbers)):
12 #This acts like a counting method
13 for j in range(0,len(Numbers)-1):
14 #It swaps each element for each iteration (j is just a random variable)
15 if (Numbers[j]>Numbers[j+1]):
16 Numbers[j],Numbers[j+1] = Numbers[j+1],Numbers[j]
17print(f"Here are the sorted numbers:{Numbers}")
18