+2 votes
in Programming Languages by (73.8k points)
edited by
How can I loop over a sequence in reverse order in Python?

1 Answer

+1 vote
by (348k points)
selected by
 
Best answer

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
+2 votes
1 answer

...