'''
Name : Midathana Pavani
ID : N190336
Class : E-1(cse2)
Description : Python program for SET OPERATIONS
'''
def union(a,b):
print("Union of A , B is : " + str(a|b))
def intersection(a,b):
print("Intersection of A , B is : " + str(a&b))
def difference(a,b):
print("Difference A-B : " + str(a-b))
print("Difference B-A : " + str(b-a))
def symmetric_difference(a,b):
print("Symmetric Difference : " + str(a^b))
def getlist(list_a,n):
list_b = list_a + [n]
return list_a,list_b
def subsets(a):
set_c = {tuple() , }
list_c = []
for i in a:
for tuple_a in set_c:
list_a , list_b = getlist(list(tuple_a) , i)
list_c.append(tuple(set(list_a)))
list_c.append(tuple(set(list_b)))
set_c.update(tuple(list_c))
print(len(set_c))
print(set_c)
a = []
n = int(input("Enter no. of elements of 1st list: ")) #taking no. of elements in list A
for i in range(n): #taking input elements
a.append(int(input("Enter element : ")))
print("Given list is : " + str(a))
b = []
m = int(input("Enter no. of elements of 2nd list: ")) #taking no. of elements in List B
for i in range(m): #taking input elements
b.append(int(input("Enter element : ")))
print("Given list is : " + str(b))
print("1.Union\n2.Intersection\n3.Difference\n4.Symmetric Difference\n5.Super set of A\n6.Super set of B\n7.Exit")
choice = True
while(choice):
opt = int(input("Select your option: "))
if(opt==1):
union(set(a),set(b))
elif(opt==2):
intersection(set(a),set(b))
elif(opt==3):
difference(set(a),set(b))
elif(opt==4):
symmetric_difference(set(a),set(b))
elif(opt==5):
print("Super set of A :")
subsets(a)
elif(opt==6):
print("Super set of B : ")
subsets(b)
elif(opt==7):
choice = False
else:
print("Choose correct option")