class Set:
arr = []
def __init__(self, lista):
self.arr = lista
def __xor__(self, other):
r1 = self - other
r2 = other - self
return r1 + r2
def __and__(self, other):
r = []
for i in self.arr:
found = False
for j in other.arr:
if i == j:
found = True
if found is True:
r.append(i)
return r
def __add__(self, other):
r = []
for i in other.arr:
r.append(i)
for i in self.arr:
found = False
for j in other.arr:
if i == j:
found = True
if found is False:
r.append(i)
return r
def __sub__(self, other):
r = []
for i in self.arr:
found = False
for j in other.arr:
if i == j:
found = True
if found is False:
r.append(i)
return r
def contains(self, x):
found = False
for i in self.arr:
if i == x:
found = True
return found
def __str__(self):
return str(self.arr)
ob1 = Set([0,1,2,3,4,5,-1])
ob2 = Set([5,6,7,8,9,0])
ob3 = ob1 - ob2
ob33 = ob2 - ob1
ob4 = ob1 + ob2
ob5 = ob1 & ob2
ob6 = ob1 ^ ob2
print("A = ", ob1)
print("B = ", ob2)
print("Difference A - B: ", ob3)
print("Difference B - A: ", ob33)
print("Union:", ob4)
print("Intersection: ", ob5)
print(ob2.contains(1))
print("Symmetric Diff: ", ob6)
a = Set(['apple','orange','banana'])
b = Set(['pink','banana','yellow','white'])
n = b - a
print(n)
Y2xhc3MgU2V0OgogICAgCiAgICBhcnIgPSBbXQogICAgCiAgICBkZWYgX19pbml0X18oc2VsZiwgbGlzdGEpOgogICAgCQogICAgICAgIHNlbGYuYXJyID0gbGlzdGEKCiAgICBkZWYgX194b3JfXyhzZWxmLCBvdGhlcik6CiAgICAgICAgCiAgICAgICAgcjEgPSBzZWxmIC0gb3RoZXIKICAgICAgICByMiA9IG90aGVyIC0gc2VsZgogICAgICAgIHJldHVybiByMSArIHIyCgogICAgZGVmIF9fYW5kX18oc2VsZiwgb3RoZXIpOgoKICAgICAgICByID0gW10KICAgICAgICBmb3IgaSBpbiBzZWxmLmFycjoKICAgICAgICAgICAgZm91bmQgPSBGYWxzZQogICAgICAgICAgICBmb3IgaiBpbiBvdGhlci5hcnI6CiAgICAgICAgICAgICAgICBpZiBpID09IGo6CiAgICAgICAgICAgICAgICAgICBmb3VuZCA9IFRydWUKICAgICAgICAgICAgaWYgZm91bmQgaXMgVHJ1ZToKICAgICAgICAgICAgICAgci5hcHBlbmQoaSkKICAgICAgICByZXR1cm4gcgoKICAgIGRlZiBfX2FkZF9fKHNlbGYsIG90aGVyKToKCiAgICAgICAgciA9IFtdCiAgICAgICAgZm9yIGkgaW4gb3RoZXIuYXJyOgogICAgICAgICAgICByLmFwcGVuZChpKQoKICAgICAgICBmb3IgaSBpbiBzZWxmLmFycjoKICAgICAgICAgICAgZm91bmQgPSBGYWxzZQogICAgICAgICAgICBmb3IgaiBpbiBvdGhlci5hcnI6CiAgICAgICAgICAgICAgICBpZiBpID09IGo6CiAgICAgICAgICAgICAgICAgICBmb3VuZCA9IFRydWUKICAgICAgICAgICAgaWYgZm91bmQgaXMgRmFsc2U6CiAgICAgICAgICAgICAgICByLmFwcGVuZChpKQogICAgICAgIHJldHVybiByCgogICAgZGVmIF9fc3ViX18oc2VsZiwgb3RoZXIpOgoKICAgICAgICByID0gW10KICAgICAgICBmb3IgaSBpbiBzZWxmLmFycjoKICAgICAgICAgICAgZm91bmQgPSBGYWxzZQogICAgICAgICAgICBmb3IgaiBpbiBvdGhlci5hcnI6CiAgICAgICAgICAgICAgICBpZiBpID09IGo6CiAgICAgICAgICAgICAgICAgICBmb3VuZCA9IFRydWUKICAgICAgICAgICAgaWYgZm91bmQgaXMgRmFsc2U6CiAgICAgICAgICAgICAgICByLmFwcGVuZChpKQogICAgICAgIHJldHVybiByCgogICAgZGVmIGNvbnRhaW5zKHNlbGYsIHgpOgogICAgICAgIGZvdW5kID0gRmFsc2UKICAgICAgICBmb3IgaSBpbiBzZWxmLmFycjoKICAgICAgICAgICAgaWYgaSA9PSB4OgogICAgICAgICAgICAgICBmb3VuZCA9IFRydWUKICAgICAgICByZXR1cm4gZm91bmQKCiAgICBkZWYgX19zdHJfXyhzZWxmKToKICAgICAgICByZXR1cm4gc3RyKHNlbGYuYXJyKQoKb2IxID0gU2V0KFswLDEsMiwzLDQsNSwtMV0pCm9iMiA9IFNldChbNSw2LDcsOCw5LDBdKQpvYjMgPSBvYjEgLSBvYjIKb2IzMyA9IG9iMiAtIG9iMQpvYjQgPSBvYjEgKyBvYjIKb2I1ID0gb2IxICYgb2IyCm9iNiA9IG9iMSBeIG9iMgpwcmludCgiQSA9ICIsIG9iMSkKcHJpbnQoIkIgPSAiLCBvYjIpCnByaW50KCJEaWZmZXJlbmNlIEEgLSBCOiAiLCBvYjMpCnByaW50KCJEaWZmZXJlbmNlIEIgLSBBOiAiLCBvYjMzKQpwcmludCgiVW5pb246Iiwgb2I0KQpwcmludCgiSW50ZXJzZWN0aW9uOiAiLCBvYjUpCnByaW50KG9iMi5jb250YWlucygxKSkKcHJpbnQoIlN5bW1ldHJpYyBEaWZmOiAiLCBvYjYpCmEgPSBTZXQoWydhcHBsZScsJ29yYW5nZScsJ2JhbmFuYSddKQpiID0gU2V0KFsncGluaycsJ2JhbmFuYScsJ3llbGxvdycsJ3doaXRlJ10pIApuID0gYiAtIGEKcHJpbnQobikK
A = [0, 1, 2, 3, 4, 5, -1]
B = [5, 6, 7, 8, 9, 0]
Difference A - B: [1, 2, 3, 4, -1]
Difference B - A: [6, 7, 8, 9]
Union: [5, 6, 7, 8, 9, 0, 1, 2, 3, 4, -1]
Intersection: [0, 5]
False
Symmetric Diff: [1, 2, 3, 4, -1, 6, 7, 8, 9]
['pink', 'yellow', 'white']