class Set:
def __init__(self, n):
self.n = n
self.set = [0]*(1000)
def read():
n = int(input("n="))
A = Set(n)
for i in range(0, n):
A.set[i] = input("elem=")
return A
def printf(set):
for i in range(0,set.n-1):
print(set.set[i], end = ", ")
print(set.set[set.n-1])
def belong(set, elem):
ok = False
for i in range(0, set.n):
if elem == set.set[i]:
ok = True;
break;
return ok
def main():
A = read()
print("Set A:")
printf(A)
B = read()
print("Set B:")
printf(B)
I = []
D = []
R = B
for index in range(0, A.n):
if belong(B, A.set[index]) is True:
I.append(A.set[index])
else:
D.append(A.set[index])
R.set[R.n] = A.set[index]
R.n =R.n + 1
print("Intersection:")
print(I)
print("Difference")
print(D)
print("Union:")
printf(R)
main()
Y2xhc3MgU2V0OgogICAgZGVmIF9faW5pdF9fKHNlbGYsIG4pOgogICAgICAgIHNlbGYubiA9IG4KICAgICAgICBzZWxmLnNldCA9IFswXSooMTAwMCkKZGVmIHJlYWQoKToKICAgIG4gPSBpbnQoaW5wdXQoIm49IikpCiAgICBBID0gU2V0KG4pCiAgICBmb3IgaSBpbiByYW5nZSgwLCBuKToKICAgICAgICBBLnNldFtpXSA9IGlucHV0KCJlbGVtPSIpCiAgICByZXR1cm4gQQoKZGVmIHByaW50ZihzZXQpOgogICAgZm9yIGkgaW4gcmFuZ2UoMCxzZXQubi0xKToKICAgICAgICBwcmludChzZXQuc2V0W2ldLCBlbmQgPSAiLCAiKQogICAgcHJpbnQoc2V0LnNldFtzZXQubi0xXSkKCmRlZiBiZWxvbmcoc2V0LCBlbGVtKToKICAgIG9rID0gRmFsc2UKICAgIGZvciBpIGluIHJhbmdlKDAsIHNldC5uKToKICAgICAgICBpZiBlbGVtID09IHNldC5zZXRbaV06CiAgICAgICAgICAgIG9rID0gVHJ1ZTsKICAgICAgICAgICAgYnJlYWs7CiAgICByZXR1cm4gb2sKCgpkZWYgbWFpbigpOgogICAgQSA9IHJlYWQoKQogICAgcHJpbnQoIlNldCBBOiIpCiAgICBwcmludGYoQSkKICAgIEIgPSByZWFkKCkKICAgIHByaW50KCJTZXQgQjoiKQogICAgcHJpbnRmKEIpCiAgICBJID0gW10KICAgIEQgPSBbXQogICAgUiA9IEIKICAgIGZvciBpbmRleCBpbiByYW5nZSgwLCBBLm4pOgogICAgICAgIGlmIGJlbG9uZyhCLCBBLnNldFtpbmRleF0pIGlzIFRydWU6CiAgICAgICAgICAgIEkuYXBwZW5kKEEuc2V0W2luZGV4XSkKICAgICAgICBlbHNlOgogICAgICAgICAgICBELmFwcGVuZChBLnNldFtpbmRleF0pCiAgICAgICAgICAgIFIuc2V0W1Iubl0gPSBBLnNldFtpbmRleF0KICAgICAgICAgICAgUi5uID1SLm4gKyAxCiAgICBwcmludCgiSW50ZXJzZWN0aW9uOiIpCiAgICBwcmludChJKQogICAgcHJpbnQoIkRpZmZlcmVuY2UiKQogICAgcHJpbnQoRCkKICAgIHByaW50KCJVbmlvbjoiKQogICAgcHJpbnRmKFIpCm1haW4oKQ==
n=elem=elem=elem=elem=elem=Set A:
1, 2, 3, 4, 5
n=elem=elem=elem=Set B:
-1, 2, 3
Intersection:
['2', '3']
Difference
['1', '4', '5']
Union:
-1, 2, 3, 1, 4, 5