Created
July 13, 2021 13:28
-
-
Save ialexpovad/7ca2e038d09c0079d565000f365ac024 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class iset(object): | |
# matrix = [] | |
def __init__(self, mat = []): | |
# method - __init__ - constructor | |
self.matrix = mat | |
def __xor__(self, other): | |
value_1 = self - other | |
value_2 = other - self | |
return iset(value_1 + value_2) | |
def __and__(self, other): | |
imatrix = [] | |
for i in self.matrix: | |
found = False | |
for j in other.matrix: | |
if i == j: | |
found = True | |
if found is True: | |
imatrix.append(i) | |
return imatrix | |
def __add__(self, other): | |
imatrix = [] | |
for item in other.matrix: | |
imatrix.append(item) | |
for i in self.matrix: | |
found = False | |
for j in other.matrix: | |
if i == j: | |
found = True | |
if found is False: | |
imatrix.append(i) | |
return imatrix | |
def __sub__(self, other): | |
imatrix = [] | |
for i in self.matrix: | |
found = False | |
for j in other.matrix: | |
if i == j: | |
found = True | |
if found is False: | |
imatrix.append(i) | |
return imatrix | |
def contains(self, value): | |
found = False | |
for i in self.matrix: | |
if i == value: | |
found = True | |
return found | |
def __str__(self): | |
return str(self.matrix) | |
if __name__ == "__main__": | |
A = iset([1,2,3,4,5]) | |
B = iset([4,5,6,7,8]) | |
C = iset([4,5,1,8,9]) | |
# differance1 = A - B - C | |
differance2 = B - A | |
intersections = A & B | |
# print(differance1) | |
q = {1,2,3,4,5} | |
w = {3,4,7,9,12} | |
e = {4,3,5,67,4} | |
print(q - w - e) | |
print() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment