There are many ways to do this problem:-
The first thing you can do is use build in reverse function.
a = ["abc", “def", "ghi"]
for i in reversed(a):
print(i)
a = ["abc", “def”, "ghi"]
for i, e in reversed(list(enumerate(a))):
print(i, e)
a = ["abc", “def”, "ghi"]
for item in a[::-1]:
print(item)
The [::-1] slice reverses the list in the for loop but it will never modify your list permanently.
Learn more about Python from an expert. Enroll in our Python Course!