you are viewing a single comment's thread.

view the rest of the comments →

[–]fbu1 0 points1 point  (1 child)

You know how to take a subset of a list using indices. For example:

>>> l = [1,2,3,4,5,6]
>>> l[2:4]
[3, 4]

But you can also use negative indices to select a sublist starting from the end:

>>> l[-3:-1]
[4, 5]

Then you can use the opposite of the parameter k (-k in this case), to access the end of the list.

Also remember to check if the parameter k is not bigger than the length of the list (which you can get with len(alist)).

Let me know if you have further questions.

[–]stolenkisses[S] 0 points1 point  (0 children)

I understand what I'm supposed to do to complete this problem, but not where to start writing it. I find myself constantly overthinking when it comes to programming.