Code Challenge: Loops - Reversed List -

(https://www.codecademy.com/courses/learn-python-3/lessons/python-functions-loops-cc/exercises/reversed)

**WHY CAN’T I use the negative indexing here. I tried the below code and I dont understand the mistake i have done **. Please help me out

def reversed_list(lst1, lst2):
  for i in range(len(lst1)):
    if lst1[i] == lst2[-i]:
     return True
    else:
       return False

    
print(reversed_list([1, 2, 3], [3, 2, 1]))
print(reversed_list([1, 5, 3], [3, 2, 1]))

Hi,

No matter how many times I’ve done for loops, there’s something comforting about just seeing i printed out and printed out in a format that helps me. In this case you’ll also probably also want to not only print i, but print lst1[i] and lst2[-1] to see what you’re working with.

If you’re not familiar, formatted string statements are great to work with. One way to write them is

print("The value of i is: {0}".format(i))
#prints The value of i is: x
# The value of i is: x
# The value of i is: x
# The value of i is: x (for however many iterations)
print("The value of lst[i] is: {0}".format(lst[i]))
# The value of  lst[i] is: x
1 Like