Decreasing for loops in Python impossible?
Solution 1:
for n in range(6,0,-1):
print n
# prints [6, 5, 4, 3, 2, 1]
Solution 2:
This is very late, but I just wanted to add that there is a more elegant way: using reversed
for i in reversed(range(10)):
print i
gives:
4
3
2
1
0
Solution 3:
for n in range(6,0,-1)
This would give you 6,5,4,3,2,1
As for
for n in reversed(range(0,6))
would give you 5,4,3,2,1,0
Solution 4:
for n in range(6,0,-1):
print n
Solution 5:
>>> range(6, 0, -1)
[6, 5, 4, 3, 2, 1]