Question: The code must be in python In this question you are going to manipulate an input list to perform some basic list operations. You have

The code must be in python

 The code must be in python In this question you are

In this question you are going to manipulate an input list to perform some basic list operations. You have to implement the function findAndRemove (L, n) that takes as input one numeric list L and an integer, n. The function performs the following actions: If n is not in L, O is returned. Otherwise, a list positions with the positions of the occurrences of n in L is constructed. The list positions must be sorted in descending order. An additional list, L_clean is created from L by removing all the occurrences of n. Note that the identity of L_clean must be different of the identity of L. In other words, L must not be changed. In the list L_clean, the difference between the maximum and the minimum value is com- puted and assigned to a variable difference. If the list L_clean is empty, than difference must be set to 0. The function returns the following tuple: (positions, L, L_clean, difference). Note that L is returned precisely to check that hasn't been changed by the operations inside the function. For instance: findAndRemove([1,0,1,1,5,7,8,9,1], 1) returns ([8, 3, 2, 0], [1, 0, 1, 1, 5, 7, 8, 9, 1], [0, 5, 7, 8, 9], 9) findAndRemove([1,0,5,1,5,7,8,5,1], 5) returns ([7, 4, 2], [1, 0, 5, 1, 5, 7, 8, 5, 1], [1, 0, 1, 7, 8, 1], 8) findAndRemove([1,0,5,1,5,7,8,5,1], 2) returns 0

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!