Define a recursive function named trim; it takes as its arguments a linked list (the head node of it) and a non-negative integer representing the index of an element in the list. The function mutates the linked list such that all elements that occur after the index is removed. Additionally, the function returns a linked list of all the elements that were moved. If the index value exceeds the length of the linked list, it should raise an IndexError. For example, if we defined a list as l1 = LN(1, LN(2, LN 3))) , calling the function would return the linked list LN(2, LN(3)), and the mutated l1 would become LN(1). You must use recursion.
def trim(l: LN, index: int) -> LN:
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here