+1 vote
in Programming Languages by (14.7k points)
edited by
How can I loop over a sequence in reverse order in Python?

1 Answer

0 votes
by (25.6k points)

To loop over a sequence in reverse, first specify the sequence in a forward direction and then call the reversed() function.

E.g.

>>> for i in reversed(range(1, 10, 1)):
...     print(i)
...
9
8
7
6
5
4
3
2
1

...