class MySet:
def __init__(self):
= 100
table_size self.table = [None] * table_size
def add(self, value):
= value % len(self.table)
index
if self.table[index] is None:
self.table[index] = []
for item in self.table[index]:
if item == value:
return False
self.table[index].append(value)
return True
def contains(self, value):
= value % len(self.table)
index if self.table[index] is None:
return False
for item in self.table[index]:
if item == value:
return True
return False
def print_table(self):
print(self.table)
= MySet()
s
print(s.add(1))
print(s.add(2))
print(s.add(3))
print(s.add(1))
print()
s.print_table()print()
print(s.contains(1))
print(s.contains(200))
True
True
True
False
[None, [1], [2], [3], None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None]
True
False