Loop backwards using indices in Python? Loop backwards using indices in Python? python python

Loop backwards using indices in Python?


Try range(100,-1,-1), the 3rd argument being the increment to use (documented here).

("range" options, start, stop, step are documented here)


In my opinion, this is the most readable:

for i in reversed(xrange(101)):    print i,


for i in range(100, -1, -1)

and some slightly longer (and slower) solution:

for i in reversed(range(101))for i in range(101)[::-1]


matomo