print("User defined Function:")
def disjoint(A, B):
Disjoint = True
for element in A:
if element in B:
Disjoint = False
break
return Disjoint
a = {1, 2, 3, 4, 5, 6, 7, 8}
b = {9, 7, 6, 11, 10, 13}
print("Set {} is: {}".format("set1:", a))
print("Set {} is: {}".format("set2:", b))
print("Set1 and Set2 are Disjoint:",disjoint(a, b))
print(" ")
print("Using inbuilt Function:")
A={1,2,3,4,5,6,7}
B={8,9,10,11,12}
print("Set {} is: {}".format("A:", A))
print("Set {} is: {}".format("B:", B))
result=A.isdisjoint(B)
print(result)
print(" ")
print("Finding A':")
class Set(set):
def __init__(self, s=(), U=None):
super().__init__(s)
self.U = U
def complement(self):
if U is None:
raise Exception('Universal set not defined')
return Set(self.U - self, self.U)
U = {10,20,30,40,50,60,70,80,90,100,110,120}
A = Set({10,20,30,40,50}, U)
print("Compliment of A:")
result=Set.complement(A)
print(result)
print(" ")
print("Finding A' using simple method::")
def complement(A):
return U - A
U = {10,20,30,40,50,60,70,80,90,100,110,120}
A = Set({10,20,30,40,50})
result=complement(A)
print("A':",result)