Question: write a Function for intersect(L, K) that takes in two lists and returns a new list consisting of all the elements of K that are

write a Function for intersect(L, K) that takes in two lists and returns a new list consisting of all the elements of K that are also in L. The result should preserve the order of elements in K and keep duplicate values. For example, if
L = [1, 2, 2, 3, 0]  K = [1, 1, 2, 5, 0]   the returned list should be [1, 1, 2, 0]. The running time of code has to be linear time.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Here is a Python function that meets the requirement... View full answer

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 Programming Questions!