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

1 Answer

0 votes
by (32.8k 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

Related questions

+2 votes
1 answer
+2 votes
1 answer
...