Q:

how to run a for loop backwards in python

    for i in range(len(item)-1, -1, -1):
        print(item[i])
4
# Python3 code to demonstrate  
# backward iteration 
# using range(N, -1, -1) 
  
# Initializing number from which  
# iteration begins  
N = 6
  
# using reversed() to perform the back iteration 
print ("The reversed numbers are : ", end = "") 
for num in range(N, -1, -1) : 
    print (num, end = " ") 
0

New to Communities?

Join the community