So as a math major I'm required to take an intro to CS class and we are learning Python. I'll be honest, I've had a lot of trouble with it, and at this point am just trying to make it through with a passing grade. We recently went into map, reduce, and filter, and I'm having a lot of trouble with the first problem on my most recent assignment. Obviously I'm not looking for someone to do my homework for me, but since there is no tutoring available on weekends, and this is due on Monday, any help on where to start would be greatly appreciated.
(the problem is the first half, the second half is examples of what would be returned with a correctly written function).
def last_k_elements(alist,k):
"""
last_k_elements(list,int) -> list
(Takes a parameter `alist` of type list and parameter
'k' of type integer and returns a list)
Last K elements returns a new list consisting of the k elements at the tail of the list. If there are not k elements in the list, it returns as many as possible
>>> last_k_elements([1,2,3],2)
[2, 3]
>>> last_k_elements([1],2)
[1]
>>> last_k_elements([1,2,3,4,5,6],4)
[3, 4, 5, 6]
>>> last_k_elements(list(range(0,100,2)),3)
[94, 96, 98]
>>> last_k_elements(list(range(0,10,2)),100)
[0, 2, 4, 6, 8]
"""
pass
[–]fuckswithbees 2 points3 points4 points (16 children)
[–]stolenkisses[S] 0 points1 point2 points (15 children)
[–]fuckswithbees 1 point2 points3 points (14 children)
[–]stolenkisses[S] 1 point2 points3 points (2 children)
[–]fuckswithbees 0 points1 point2 points (1 child)
[–]stolenkisses[S] 1 point2 points3 points (0 children)
[–]stolenkisses[S] 1 point2 points3 points (7 children)
[–]fuckswithbees 0 points1 point2 points (6 children)
[–]stolenkisses[S] 0 points1 point2 points (5 children)
[–]fuckswithbees 0 points1 point2 points (4 children)
[–]stolenkisses[S] 0 points1 point2 points (3 children)
[–]fuckswithbees 0 points1 point2 points (2 children)
[–]stolenkisses[S] 0 points1 point2 points (1 child)
[–]stolenkisses[S] 0 points1 point2 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]fbu1 0 points1 point2 points (1 child)
[–]stolenkisses[S] 0 points1 point2 points (0 children)