哈希映射实现问题-python

哈希映射实现问题-python,python,hashmap,Python,Hashmap,我正试图用python实现我自己的哈希映射,但insert方法仍然存在问题。 如果self.u数组[散列(项)]为无: 索引器:列表索引超出范围 class My_Hash: def __init__(self): self.size = 10 self.the_array = self.size*[None] self.count = 0 def __len__(self): return self.count def is_empty(self):

我正试图用python实现我自己的哈希映射,但insert方法仍然存在问题。 如果self.u数组[散列(项)]为无: 索引器:列表索引超出范围

class My_Hash:

def __init__(self):
    self.size = 10
    self.the_array = self.size*[None]
    self.count = 0

def __len__(self):
    return self.count

def is_empty(self):
    return len(self) == 0

def is_full(self):
    return len(self)>=len(self.the_array)

def hash(self,item):
     value= (ord(item[0]) + ord(item[1]))%self.size
     print (value)
     return value

def resize(self):
    self.size = self.size^2
    new_size = len(self.the_array)^2
    for i in new_size:
        self.the_array.append(None)

def insert(self,item):
   if self.is_full():
       self.resize()
   if self.the_array[hash(item)] is None:  #this is where the error occurs
    self.the_array[hash(item)]= item
    self.count+=1
   else:
       new_hash = hash(item)
       hash_attempt = 0
       while not(self.the_array[new_hash] is None):
           new_hash = ((new_hash + new_hash^2)*3)%len(self.the_array)
           hash_attempt +=1
           if hash_attempt > len(self.the_array)/2:
                self.resize()
       self.the_array[new_hash]= item

为什么要实现HashMap?你知道一些Python字典,对吧?
hash()
应该是
self.hash()
?你是在调用class方法而不是instance方法吗?我正在为一个大学项目实现我自己的方法。我认为将其更改为self.hash()解决了这个问题。谢谢您。