for the following assignment:
Create a function named reversed_list()
that takes two lists of the same size as parameters named lst1
and lst2
.
The function should return True
if lst1
is the same as lst2
reversed. The function should return False
otherwise.
For example, reversed_list([1, 2, 3], [3, 2, 1])
should return True
.
solution
def reversed_list(lst1,lst2):
for index in range(len(lst1)):
if lst1[index] != lst2[len(lst2) - index - 1]:
return False
return True
print(reversed_list([1, 2, 3], [3, 2, 1]))
print(reversed_list([1, 5, 3], [3, 2, 1]))
- when I try to check wether the lists are reversed except to give a true statement when the condition is met instead of checking wether its false it gives me 2 true statements while the conditions arent met for the second list.
- why doesnt an else work for the second return command?
thanks in advance!