Question: Provide solution in python language. P8.13 Amultiset is a collection in which each item occurs with a frequency. You might have a multiset with two
Provide solution in python language.
P8.13 Amultiset is a collection in which each item occurs with a frequency. You might have a multiset with two bananas and three apples, for example. A multiset can be implemented as a dictionary in which the keys are the items and the values are the frequencies. Write Python functions union, intersection, and difference that take two such dictionaries and return a dictionary representing the multiset union, intersec- tion, and difference. In the union, the frequency of an item is the sum of the frequen- cies in both sets. In the intersection, the frequency of an item is the minimum of the frequencies in both sets. In the difference, the frequency of an item is the difference of the frequencies in both sets, but not less than zero
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
