class Set:
set = []
def __init__(self,Thelist):
self.set = Thelist
def __sub__(self,other):
out = []
for el in self.set:
found = False
for el2 in other.set:
if el == el2:
found = True
break
if found is False:
out.append(el)
return out
def __add__(self,other):
out = []
for i in other.set:
out.append(i)
for el in self.set:
found = False
for el2 in other.set:
if el == el2:
found = True
break
if found is False:
out.append(el)
out.sort()
return out
def __and__(self,other):
out = []
for el in self.set:
found = False
for el2 in other.set:
if el == el2:
found = True
break
if found is True:
out.append(el)
return out
def fn():
list1 = [1,2,3,4,5,6,7,102]
print(list1)
list2 = [10,101,2,3,102,202]
list2.sort()
print(list2)
set1 = Set(list1)
set2 = Set(list2)
print("Intersect: ",set1&set2)
print("Union",set1+set2)
print("Diff",set1-set2)
fn()
Y2xhc3MgU2V0OgoKICAgIHNldCA9IFtdCgogICAgZGVmIF9faW5pdF9fKHNlbGYsVGhlbGlzdCk6CiAgICAgICAgc2VsZi5zZXQgPSBUaGVsaXN0CgogICAgZGVmIF9fc3ViX18oc2VsZixvdGhlcik6CiAgICAgICAgb3V0ID0gW10KICAgICAgICBmb3IgZWwgaW4gc2VsZi5zZXQ6CiAgICAgICAgICAgIGZvdW5kID0gRmFsc2UKICAgICAgICAgICAgZm9yIGVsMiBpbiBvdGhlci5zZXQ6CiAgICAgICAgICAgICAgICBpZiBlbCA9PSBlbDI6CiAgICAgICAgICAgICAgICAgICBmb3VuZCA9IFRydWUKICAgICAgICAgICAgICAgICAgIGJyZWFrCiAgICAgICAgICAgIGlmIGZvdW5kIGlzIEZhbHNlOgogICAgICAgICAgICAgICBvdXQuYXBwZW5kKGVsKQogICAgICAgIHJldHVybiBvdXQKCiAgICBkZWYgX19hZGRfXyhzZWxmLG90aGVyKToKICAgICAgICBvdXQgPSBbXQogICAgICAgIGZvciBpIGluIG90aGVyLnNldDoKICAgICAgICAgICAgb3V0LmFwcGVuZChpKQogICAgICAgIGZvciBlbCBpbiBzZWxmLnNldDoKICAgICAgICAgICAgZm91bmQgPSBGYWxzZQogICAgICAgICAgICBmb3IgZWwyIGluIG90aGVyLnNldDoKICAgICAgICAgICAgICAgIGlmIGVsID09IGVsMjoKICAgICAgICAgICAgICAgICAgIGZvdW5kID0gVHJ1ZQogICAgICAgICAgICAgICAgICAgYnJlYWsKICAgICAgICAgICAgaWYgZm91bmQgaXMgRmFsc2U6CiAgICAgICAgICAgICAgIG91dC5hcHBlbmQoZWwpCiAgICAgICAgb3V0LnNvcnQoKQogICAgICAgIHJldHVybiBvdXQKCgoKICAgIGRlZiBfX2FuZF9fKHNlbGYsb3RoZXIpOgogICAgICAgIG91dCA9IFtdCiAgICAgICAgZm9yIGVsIGluIHNlbGYuc2V0OgogICAgICAgICAgICBmb3VuZCA9IEZhbHNlCiAgICAgICAgICAgIGZvciBlbDIgaW4gb3RoZXIuc2V0OgogICAgICAgICAgICAgICAgaWYgZWwgPT0gZWwyOgogICAgICAgICAgICAgICAgICAgIGZvdW5kID0gVHJ1ZQogICAgICAgICAgICAgICAgICAgIGJyZWFrCiAgICAgICAgICAgIGlmIGZvdW5kIGlzIFRydWU6CiAgICAgICAgICAgICAgICBvdXQuYXBwZW5kKGVsKQogICAgICAgIHJldHVybiBvdXQKCmRlZiBmbigpOgogICAgbGlzdDEgPSBbMSwyLDMsNCw1LDYsNywxMDJdCiAgICBwcmludChsaXN0MSkKICAgIGxpc3QyID0gWzEwLDEwMSwyLDMsMTAyLDIwMl0KICAgIGxpc3QyLnNvcnQoKQogICAgcHJpbnQobGlzdDIpCiAgICBzZXQxID0gU2V0KGxpc3QxKQogICAgc2V0MiA9IFNldChsaXN0MikKICAgIHByaW50KCJJbnRlcnNlY3Q6ICIsc2V0MSZzZXQyKQogICAgcHJpbnQoIlVuaW9uIixzZXQxK3NldDIpCiAgICBwcmludCgiRGlmZiIsc2V0MS1zZXQyKQpmbigp
[1, 2, 3, 4, 5, 6, 7, 102]
[2, 3, 10, 101, 102, 202]
Intersect: [2, 3, 102]
Union [1, 2, 3, 4, 5, 6, 7, 10, 101, 102, 202]
Diff [1, 4, 5, 6, 7]