Question
------------------------------ Use PYTHON 2,7 ----------------------------------- Please DONT POST ANYTHING if you can't do it FULLY and if you are not SURE FROM YOUR CODE because
------------------------------ Use PYTHON 2,7 -----------------------------------
Please DONT POST ANYTHING if you can't do it FULLY and if you are not SURE FROM YOUR CODEbecause I dont want to post question again
Also, Please SHOW YOUR WORKING CODE WITH A SCREEN SHOT
# Implementation of the Set ADT container using a Python list.
class Set :
# Creates an empty set instance.
def __init__( self ):
self._theElements = list()
# Returns the number of items in the set.
def __len__( self ):
return len( self._theElements )
# Determines if an element is in the set.
def __contains__( self, element ):
return element in self._theElements
# Adds a new unique element to the set.
def add( self, element ):
if element not in self :
self._theElements.append( element )
# Removes an element from the set.
def remove( self, element ):
assert element in self, "The element must be in the set."
self._theElements.remove( item )
# Determines if two sets are equal.
def __eq__( self, setB ):
if len( self ) != len( setB ) :
return False
else :
return self.isSubsetOf( setB )
# Determines if this set is a subset of setB.
def isSubsetOf( self, setB ):
for element in self :
if element not in setB :
return False
return True
# Creates a new set from the union of this set and setB.
def union( self, setB ):
newSet = Set()
newSet._theElements.extend( self._theElements )
for element in setB :
if element not in self :
newSet._theElements.append( element )
return newSet
1) Complete the Set ADT by implementing intersect(), difference(), and symmetric difference) 2) Hodify the Set() constructor to accept an optional variable argument to which a collection of initial values can be passed to initialize the set. The prototype for the new constructor should look as follows: def Seti self, "initElements - None ) It can then be used as shom here to create a set initialized with the given values: s = set( 150, 75, 23, 86, 49 ) 3) Add a new operation to the Set ADT to test for a proper subset. Given tuo sets, A and B, A is a proper subset of B, ifA is a subset of B and A doe:s not equal B 4) Add the str() method to the Set implementation to allow a user to print the contents of the set. The resulting string should look similar to that of a list, except you are to use curly braces to surround the elements. 5) Add Python operator methods to the Set class that can be used to perform similar operations to those already detined by named methods: Operator Method Syntactic Sugar Current Hethod add( setB) self setB self setB self - setB unioni setB interset setB ) difference( setB symmetric_ difference setB) isSubsetofi setB sub setB xor( setB) selfStep 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