Мне нужна помощь в создании функции вставки, которая добавляет значения в хеш-таблицу, где каждая позиция таблицы является списком. Если есть столкновение, значение просто добавляется в список в правильном положении.Python Hashing со списками
class MyChainHashTable:
def __init__(self, capacity):
self.capacity = capacity
self.slots = []
for i in range(self.capacity):
self.slots.append([])
def __str__(self):
info = ""
for items in self.slots:
info += str(items)
return info
def __len__(self):
count = 0
for i in self.slots:
count += len(i)
return count
def hash_function(self, key):
i = key % self.capacity
return i
def insert(self, key):
#need help
#this should insert each value into seperate lists, and if there is collision
#it should add the value to make a list with +1 positions.
#eg. [26][][54, 93][][17, 43][31][][][][][][][77, 90]