7. Reverse


#1

x = ['r','b','a']
for i in range(len(x)):
print x[-(i+1)]

So I found this code while looking online...but I don't understand this part "[-(i+1)]". Can somebody explain?


#2

I have inserted some print statements in the original code. Check it out if it helps

x = ['r','b','a']
for i in range(len(x)):
    print "The current index i is ",i
    print "but -(i+1) will be ",-(i+1)
    print "The element at position ",-(i+1), " is ", x[-(i+1)],"\n"

or

TEST IT HERE


#3

Great, thank you so much! :smile: I didn't understand negative index but now I get it!