I am currently struggling with this code challenge.
I am confused as to why this answer returns two True statements:
def reversed_list(lst1, lst2):
for index in range(len(lst1)):
if lst1[index] == lst2[len(lst2) - 1 - index]:
return True
return False
print(reversed_list([1, 2, 3], [3, 2, 1]))
print(reversed_list([1, 5, 3], [3, 2, 1]))
While (what I think is) the opposite of the function returns the correct answer of one True and one False statement:
def reversed_list(lst1, lst2):
for index in range(len(lst1)):
if lst1[index] != lst2[len(lst2) - 1 - index]:
return False
return True
print(reversed_list([1, 2, 3], [3, 2, 1]))
print(reversed_list([1, 5, 3], [3, 2, 1]))
Can somebody explain to me what part of the code makes this the case, as in what causes the second True statement to be returned in the first code, and what causes the False statement to be returned in the second code?
Thank you!