Assume you are given two lists, L1 and L2.
The lecture's intersect keeps each common value only once, so two lists of three 7s intersect to [7]. Write common_with_repeats(L1, L2), which instead keeps a value as many times as both lists can supply it: every element of L2 can be matched with at most one element of L1. Go through L1 from the front; an element goes into the result when some element of L2 equal to it has not been matched yet, and that element of L2 then counts as matched. Return the new list, in the order the elements appear in L1.
Neither L1 nor L2 may be changed.
print(common_with_repeats([3, 5, 2], [2, 3, 5, 9])) # [3, 5, 2] print(common_with_repeats([7, 7, 7], [7, 7])) # [7, 7] print(common_with_repeats([1, 2, 2, 3, 2], [2, 3, 3, 2])) # [2, 2, 3]