Search for question
Question

4. (9 pts) Implement the 'MySet' class using Python's object-oriented programming principles.

This class should have the same functionality as the built-in `set` class in Python. Base your

implementation on a dictionary.

The 'MySet' class should support the following methods:

a) __init__(self, iterable=None)': Initializes a new instance of MySet. If an optional

`iterable' argument is provided, it should be used to initialize the set with its elements.

(1 pts)

b) add(self, element)': Adds the specified `element to the set, if it is not already present.

(1 pts)

c) `remove(self, element)`: Removes the specified `element` from the set, if it is present.

Raises a 'KeyError' if the element is not found in the set. (1 pts)

d) clear(self): Removes all elements from the set, leaving it empty. (1 pts)

e) 'copy(self): Returns a shallow copy of the set. (1 pts)

f) union(self, other_set)`: Returns a new set that is the union of the current set and

`other_set'. (1 pts)

g) 'intersection(self, other_set)`: Returns a new set that is the intersection of the current set

and 'other_set. (1 pts)

h) 'difference(self, other_set)': Returns a new set that contains the elements present in the

current set but not in 'other_set'. (1 pts)

i) issubset(self, other_set)': Returns 'True' if the current set is a subset of 'other_set',

'False' otherwise. (1 pts)

Ensure that your implementation adheres to the principles of object-oriented programming in

Python and retains the same functionality as the built-in 'set' class.

Fig: 1