reverse of list in python code example
Example 1: reverse list python
>>> the_list = [1,2,3]
>>> reversed_list = the_list.reverse()
>>> list(reversed_list)
[3,2,1]
OR
>>> the_list = [1,2,3]
>>> the_list[::-1]
[3,2,1]
Example 2: python reverse list
list.reverse()
Example 3: reverse element in a list in python 3
my_list = [1, 7, 9, 11, 12, 20]
# Reverse a list by using a slice
print(my_list[::-1])
Example 4: list slicing reverse python
#This option produces a reversed copy of the list. Contrast this to mylist.reverse() which
#reverses the original list
>>> mylist
[1, 2, 3, 4, 5]
>>> mylist[::-1]
[5, 4, 3, 2, 1]
Example 5: reverse a list in python
a = ['a', 'b', '4', '5', 'd'] #reverse the List
print(list(reversed(a)))
Example 6: python reverse list
# Operating System List
systems = ['Windows', 'macOS', 'Linux']
print('Original List:', systems)
# Reversing a list
#Syntax: reversed_list = systems[start:stop:step]
reversed_list = systems[::-1]
# updated list
print('Updated List:', reversed_list)