问题描述
我是 DataStructure 的新手,你能给我建议,在 python 中实现哈希表的最佳方法或使其进步
class ChainingHashTable:
def __init__(self,value):
self.value = value
self.array = [[] for _ in range(value)]
def hash(self,keyvalue):
hash_key = sum(ord(i) for i in keyvalue)
index_in_array = hash_key % self.value
self.array[index_in_array].append(keyvalue)
def display_hashtable(self):
for i in range(len(self.array)):
print(i,end='')
for j in self.array[i]:
print('-->',end=j)
print()
s = ChainingHashTable(10)
s.hash('hello')
s.hash('good')
s.hash('Abracadabra')
s.hash('Poter')
s.display_hashtable()
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)