-
Notifications
You must be signed in to change notification settings - Fork 0
/
Operator_overloading.py
69 lines (61 loc) · 1.65 KB
/
Operator_overloading.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import copy
class OrderSet():
def __init__(self, Set):
self.Set = Set
def __and__(self, other):
set1 = copy.deepcopy(self.Set)
set2 = copy.deepcopy(other.Set)
Set = []
for i in set1:
if i in set2:
Set.append(i)
return Set
def __or__(self, other):
set1 = copy.deepcopy(self.Set)
set2 = copy.deepcopy(other.Set)
Set = []
for i in range(len(set1)):
Set.append(i)
for i in range(len(set2)):
if i not in Set:
Set.add(i)
return Set
def __xor__(self, other):
set1 = copy.deepcopy(self.Set)
set2 = copy.deepcopy(other.Set)
Set = []
for i in set1:
if i not in set2:
Set.append(i)
for i in set2:
if i not in set1:
Set.append(i)
return Set
def __eq__(self, other):
set1 = copy.deepcopy(self.Set)
set2 = copy.deepcopy(other.Set)
if set1 == set2:
return True
else:
return False
def __ne__(self, other):
set1 = copy.deepcopy(self.Set)
set2 = copy.deepcopy(other.Set)
if set1 == set2:
return False
else:
return True
def __contains__(self, other):
set1 = copy.deepcopy(self.Set)
set2 = copy.deepcopy(other.Set)
k = 0
for i in set1:
for j in set2:
if i == j:
k += 1
if k == len(set1):
return True
elif k == len(set2):
return True
else:
return False