Answered step by step
Verified Expert Solution
Question
1 Approved Answer
PLEASE ANSWER IN PYTHON This is a programming question. Upload the .py file with the answer. Make sure your solution is readable, works, and follows
PLEASE ANSWER IN PYTHON
This is a programming question. Upload the .py file with the answer. Make sure your solution is readable, works, and follows the Python coding style learned in class. Proper indentation is required. Write a class called Set that implements a set object similar to the builtin set class we studied. A Set object is a collection of objects with the semantics of a mathematical set: objects stored in a Set have no duplicates, i.e. adding an object x to a Set should check first if x already exists in the set using the equality operator and should add x to the set only if x did no belong there previously. The order of the elements in a Set is arbitrary The Set class must have the following "public" methods constructor, taking a parameter that is a list. The new Set object will contain the elements from the list, excluding . str__(self): returns a string representation of the set that includes all elements' string representation . _add_(self, other): implements the union set operation and returns a new Set object with all elements of this (self) _sub--(self, other): implements the set difference operation and returns a new Set object with all elements of this duplicates. If the list is empty (I) then a new Set object is created with no elements Set([0,1,2]). str__() should return "(0,1,2]", with the order of elements being arbitrary. object and of the other set, excluding duplicates (self) object that do not belong to the other set. mul_(self, other): implements the set intersection operation and returns a new Set object with all elements of this (self) object that also belong to the other set contains-(self, elem): returns True if the object elem belong to the current (self) set and False otherwise. This standard function is called by the in operator, as in: x in A set . insert(self, x): inserts object x to the current set (self) if x was not already in the set. to_list(self): returns a new list object with the elements from the current (self) set object. Implementation requirements: class Set should not use in any way the standard classes set and dict to implement its methods or for storing the elements. The elements must be stored in a list object. Here are some examples how the Set class could be usedStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started