This question is based on Discrete Structures, on the concept of sets. If you kn
ID: 3786063 • Letter: T
Question
This question is based on Discrete Structures, on the concept of sets. If you know this coupled with Python programming, maybe you can answer this question.
Here is an Example of the first operation:
#5.1
def IsEmpty(a):
A = set(a)
if len(A) <= 0:
return True
else:
return False
How do I write these operations in Python?
A My Set Operations is a collection of functions, on which the following set operations are defined: miles Empty(A): Returns T if the set A is empty (A = 0), F otherwise. My Disjoint (A, B): Returns T if intersection of the set A and set B is non-empty (A Intersection B notequalto O), F otherwise. my Intersection (A, B): Returns the intersection of the set A and set B (A Intersection B). my Union (A, B): Returns the union of the set A and set B (A Union B). my Difference (A, B): Returns the complement of the set A and set B (A B). my Sym Difference (A, B): Returns the symmetric difference of the set A and set B (A B). Write a collection of My Set Operations in Python.Explanation / Answer
def myIsEmpty(a):
A = set(a)
if len(A) <= 0:
return True
else:
return False
def myDisjoint(a,b):
A = set(a)
B = set(b)
if myIsEmpty(myIntersection(A, B) ):
return True
else:
return False
def myIntersection(a,b):
A = set(a)
B = set(b)
return A.intersection(B)
def myUnion(a,b):
A = set(a)
B = set(b)
return A.union(B)
def myDifference(a,b):
A = set(a)
B = set(b)
return A.difference(B)
def mySymDifference(a,b):
A = set(a)
B = set(b)
return A.symmetric_difference(B)
my_set = {1,2,3,4,3,2}
my_set1 = {1,2,3,4}
//test samples are as follows:
print myIsEmpty(my_set)
print myIsEmpty(my_set1)
print myDisjoint(my_set, my_set1)
print myIntersection(my_set, my_set1)
print myUnion(my_set, my_set1)
print myDifference(my_set, my_set1)
print mySymDifference(my_set, my_set1)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.