Reversing indexing of list in reverse the List in Python. It could do easily done by using Slice Notation in python.
list[::-1]
Example reverse indexing in Python
Simple example code, Reverse a list.
list1 = [1, 2, 3, 4, 5, 6, 0]
reverse = list1[::-1]
print(reverse)
Another solution using reversed instead of slicing with [::-1]:
list1 = [1, 2, 3, 4, 5, 6, 0]
inverse_items = []
for item in reversed(list1):
inverse_items.append(item)
print(inverse_items)
Output:
Reverse string using Reverse indexing in Python
str1 = "Python"
print(str1[::-1])
Output: nohtyP
Do comment if you have any doubts and suggestions on this Python index topic.
Note: IDE: PyCharm 2021.3.3 (Community Edition)
Windows 10
Python 3.10.1
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.