Question: def insertList(L, sL, p,c) : Specification: L and sL are lists, p is an integer between 0 and len( L (inclusive of 0 and len(


def insertList(L, sL, p,c) : Specification: L and sL are lists, p is an integer between 0 and len( L (inclusive of 0 and len( L) ), and c is a non-negative integer. The function returns a new list obtained by inserting c copies of sL into L, immediately before the element at index p. If p equals len (L), the c copies of sL are inserted at the end of L. Examples - insertList([3, 2, 8, 4], [1, 2], 3, 4) returns [3,2,8,1,2,1,2,1,2,1,2,4]. In this example, we want to insert 4 copies of the list [1,2] immediately before the element at index 3 in the list [3,2,8,4] - insertList([1, 2, 3, 4], [8, 9], 0, 2) returns [8,9,8,9,1,2,3,4] - insertList([1, 2, 3, 4], [8, 9], 1, 2) returns [1,8,9,8,9,2,3,4] - insertList([1, 2, 3, 4], [8, 9], 4, 2) returns [1,2,3,4,8,9,8,9] - insertList([1, 2, 3, 4], [8, 9], 4, 4) returns [1,2,3,4,8,9,8,9,8,9,8,9] Problem 2: Write a function with the following signature def matrixTranspose(L): Specification: L is a nested list representation of an mn matrix M. The function is required to return the nested list representation of the transpose of M, denoted MT, which is an nm matrix. For example, if M=[32104511] then MT=31052411. Therefore, if L=[[3,10,5],[2,4,11]] then the function should return the list [[3,2],[10,4],[5,11]]. Examples - matrixTranspose([[3, 10, 5], [2,4,11]]) should return [[3,2],[10,4],[5,11]] - matrixTranspose([[2], [5], [7]]) should return [[2,5,7]] - matrixTranspose([[2, 3], [5, 7], [7, 9], [9, 11]]) should return [[2,5,7,9],[3,7,9,11]] - matrixTranspose([[1, 1, 1, 1]]) should return [[1], [1], [1], [1]]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
