class Set:
arr = []
def __init__(self, lista):
self.arr = lista
def __xor__(self, other):
r1 = self - other
r2 = other - self
return Set(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(type(ob6))
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)
Y2xhc3MgU2V0OgoKICAgIGFyciA9IFtdCgogICAgZGVmIF9faW5pdF9fKHNlbGYsIGxpc3RhKToKCiAgICAgICAgc2VsZi5hcnIgPSBsaXN0YQoKICAgIGRlZiBfX3hvcl9fKHNlbGYsIG90aGVyKToKCiAgICAgICAgcjEgPSBzZWxmIC0gb3RoZXIKICAgICAgICByMiA9IG90aGVyIC0gc2VsZgogICAgICAgIHJldHVybiBTZXQocjEgKyByMikKCiAgICBkZWYgX19hbmRfXyhzZWxmLCBvdGhlcik6CgogICAgICAgIHIgPSBbXQogICAgICAgIGZvciBpIGluIHNlbGYuYXJyOgogICAgICAgICAgICBmb3VuZCA9IEZhbHNlCiAgICAgICAgICAgIGZvciBqIGluIG90aGVyLmFycjoKICAgICAgICAgICAgICAgIGlmIGkgPT0gajoKICAgICAgICAgICAgICAgICAgIGZvdW5kID0gVHJ1ZQogICAgICAgICAgICBpZiBmb3VuZCBpcyBUcnVlOgogICAgICAgICAgICAgICByLmFwcGVuZChpKQogICAgICAgIHJldHVybiByCgogICAgZGVmIF9fYWRkX18oc2VsZiwgb3RoZXIpOgoKICAgICAgICByID0gW10KICAgICAgICBmb3IgaSBpbiBvdGhlci5hcnI6CiAgICAgICAgICAgIHIuYXBwZW5kKGkpCgogICAgICAgIGZvciBpIGluIHNlbGYuYXJyOgogICAgICAgICAgICBmb3VuZCA9IEZhbHNlCiAgICAgICAgICAgIGZvciBqIGluIG90aGVyLmFycjoKICAgICAgICAgICAgICAgIGlmIGkgPT0gajoKICAgICAgICAgICAgICAgICAgIGZvdW5kID0gVHJ1ZQogICAgICAgICAgICBpZiBmb3VuZCBpcyBGYWxzZToKICAgICAgICAgICAgICAgIHIuYXBwZW5kKGkpCiAgICAgICAgcmV0dXJuIHIKCiAgICBkZWYgX19zdWJfXyhzZWxmLCBvdGhlcik6CgogICAgICAgIHIgPSBbXQogICAgICAgIGZvciBpIGluIHNlbGYuYXJyOgogICAgICAgICAgICBmb3VuZCA9IEZhbHNlCiAgICAgICAgICAgIGZvciBqIGluIG90aGVyLmFycjoKICAgICAgICAgICAgICAgIGlmIGkgPT0gajoKICAgICAgICAgICAgICAgICAgIGZvdW5kID0gVHJ1ZQogICAgICAgICAgICBpZiBmb3VuZCBpcyBGYWxzZToKICAgICAgICAgICAgICAgIHIuYXBwZW5kKGkpCiAgICAgICAgcmV0dXJuIHIKCiAgICBkZWYgY29udGFpbnMoc2VsZiwgeCk6CiAgICAgICAgZm91bmQgPSBGYWxzZQogICAgICAgIGZvciBpIGluIHNlbGYuYXJyOgogICAgICAgICAgICBpZiBpID09IHg6CiAgICAgICAgICAgICAgIGZvdW5kID0gVHJ1ZQogICAgICAgIHJldHVybiBmb3VuZAoKICAgIGRlZiBfX3N0cl9fKHNlbGYpOgogICAgICAgIHJldHVybiBzdHIoc2VsZi5hcnIpCgpvYjEgPSBTZXQoWzAsMSwyLDMsNCw1LC0xXSkKb2IyID0gU2V0KFs1LDYsNyw4LDksMF0pCm9iMyA9IG9iMSAtIG9iMgpvYjMzID0gb2IyIC0gb2IxCm9iNCA9IG9iMSArIG9iMgpvYjUgPSBvYjEgJiBvYjIKb2I2ID0gb2IxIF4gb2IyCnByaW50KHR5cGUob2I2KSkKcHJpbnQoIkEgPSAiLCBvYjEpCnByaW50KCJCID0gIiwgb2IyKQpwcmludCgiRGlmZmVyZW5jZSBBIC0gQjogIiwgb2IzKQpwcmludCgiRGlmZmVyZW5jZSBCIC0gQTogIiwgb2IzMykKcHJpbnQoIlVuaW9uOiIsIG9iNCkKcHJpbnQoIkludGVyc2VjdGlvbjogIiwgb2I1KQpwcmludChvYjIuY29udGFpbnMoMSkpCnByaW50KCJTeW1tZXRyaWMgRGlmZjogIiwgb2I2KQo=
<class '__main__.Set'>
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]