How is that i get the reverse iteration using the following code. Should I be using the reduce function or something?
Example:
for i in range(4):
print i ////0 1 2 3
how do i print the same in the reverse order
3 2 1 0
a=[5,2,1,4,3]
I also want to print the above array in reverse using the index and not a[::-1]
i.e,i want to first print
a[4] //get index starting from last how to achieve this
a[3]
a[2]
a[1]
a[0]
range(4, 0, -1)creates a reverse range. Don't understand second part of your quetion, though.range(4, 0, -1)is notreversed(range(4))range(3, -1, -1)and solution withreversedis betterfor i, x in reversed(list(enumerate(a)))will suit better thanfor i in range(len(a), -1, -1)?