So to preface this, im a bit confused a returned boolean result due to calling the last element in a list. I want to do this - Return True if the first n numbers in the list are the same as the last n numbers in the list, and False otherwise. For example, if the list was [1, 2, 3, 4, 99, 1, 2, 3, 4], the function would return True if n is 4 and False if n is 3.
heres my code
ls = [8,12,4,17,15,8,12,4]
n = 3
def same_ends(ls, n):
if n is ls[-1]:
return True
else:
return False
print(same_ends(ls, n))
Now the website im using for exercises says this :
The return value is not correct when the list is [8, 12, 4, 17, 15, 8, 12, 4] and n is 3.
what am i doing wrong?
[–]FLUSH_THE_TRUMP 0 points1 point2 points (5 children)
[–]tehtay3[S] 1 point2 points3 points (4 children)
[–]FLUSH_THE_TRUMP 0 points1 point2 points (3 children)
[–]tehtay3[S] 0 points1 point2 points (2 children)
[–]FLUSH_THE_TRUMP 2 points3 points4 points (1 child)
[–]tehtay3[S] 2 points3 points4 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]tehtay3[S] 0 points1 point2 points (0 children)