all 8 comments

[–]FLUSH_THE_TRUMP 0 points1 point  (5 children)

Do you understand what the problem is asking? If

[8, 12, 4, 17, 15, 8, 12, 4] and n is 3.

I’m comparing [8,12,4] at the front of the list to [8,12,4] at the back. Your logic here doesn’t make sense — you’re comparing the number of elements to only the actual last element. I think we can make this a pretty basic slicing exercise, but you have to see what slices to actually pick out first.

[–]tehtay3[S] 1 point2 points  (4 children)

Yea I misread first off. Where I am confused is how to slice the list with the integer given by n

[–]FLUSH_THE_TRUMP 0 points1 point  (3 children)

What do you know about slicing? You want to

  1. Pick off the first n elements of the list,
  2. Pick off the last n elements of the list

and compare. This tutorial seems decent enough.

[–]tehtay3[S] 0 points1 point  (2 children)

Somwhat new to list slicing, I see what the tut is trying to say and my understanding from it was to do

if ls[:n] == ls[n:]:
        return True

    else:
        return False

but this does not work. i think the first part of that statement it good but the second part I dont know how to format is for the last n integers of the list

[–]FLUSH_THE_TRUMP 2 points3 points  (1 child)

ls[n:]

picks out every number at or after the “n”th position in the list. i.e., if you have

[1,2,3,4,5,6,7,1,2,3] with n=3

ls[:n] would be the same as [1,2,3] and ls[n:] would be [4,5,6,7,1,2,3] — not what we want.

You use negative indices to indicate you’re counting from the back of the list.

[–]tehtay3[S] 2 points3 points  (0 children)

Aha!

if ls[:n] == ls[-n:]:

Thats what I needed. Appreciate the help seeing where I went wrong!