def reversed_list(lst1, lst2):
for n in range(len(lst1)):
if lst1[n] != lst2[- n - 1]:
return False
else:
return True
print(reversed_list([1, 2, 3], [3, 2, 1])) “True”
print(reversed_list([1, 5, 3], [3, 2, 1])) “True”
def reversed_list(lst1, lst2):
for n in range(len(lst1)):
if lst1[n] != lst2[- n - 1]:
return False
else:
return True
print(reversed_list([1, 2, 3], [3, 2, 1])) “True”
print(reversed_list([1, 5, 3], [3, 2, 1])) “True”
Hey there! For future questions, here’s some info: How do I format code in my post?
Think about your control flow step by step.
n = 0
lst1[0] is not equal to lst2[-1]
lst1[0]
= 1 and lst2[-1]
also = 1, so we go to the else
statementelse
says to return True
It seems the problem is your loop never gets past the first case n = 0
This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.