1>>> the_list = [1,2,3]
2>>> reversed_list = the_list.reverse()
3>>> list(reversed_list)
4[3,2,1]
5
6OR
7
8>>> the_list = [1,2,3]
9>>> the_list[::-1]
10[3,2,1]
1
2# ----------- HOW TO REVERSE AN ORDERED LIST ----------- #
3
4myList = [-1, 3, 8, 2, 9, 5]
5sorted(myList,reverse=True)
6
7>>> [9, 8, 5, 3, 2, -1]
8
9OR
10
11order_list = sorted(input1)
12order_list[::-1]
13
14>>> [9, 8, 5, 3, 2, -1]
15
1my_list = [1, 2, 3]
2my_list.reverse() # my_list is modified
3print(my_list) # '[3, 2, 1]'
4my_revert = my_list[::-1] # my_list stays [3, 2, 1]
5print(my_revert) # '[1, 2, 3]'
6# Item by item reverse with range(<start>, <end>, <step>)
7for i in range(len(my_list), 0, -1): # my_list is [3, 2, 1]
8 print(my_list[i-1]) # '1' '2' '3'
9for i in reversed(range(len(my_list))):
10 print(my_list[i]) # '1' '2' '3'
1# The Reverse operation - Python 3:
2Some_List = [1, 2, 3, 4, 1, 2, 6]
3Some_List.reverse()
4print(Some_List)
5# Result: [6, 2, 1, 4, 3, 2, 1]
1arr = [2,5,32,86,4,131,97]
2
3# reverse without modifying input, using range:
4for i in range(len(arr)-1, -1, -1):
5 print(arr[i])
6
7# reverse and modifying input:
8arr.reverse()
9
10