如何解决我已经在 python 中实现了哈希表为什么使用 if 条件 len(element) ==2?
我一直在试图弄清楚为什么在下面的代码 if len(element) == 2 and element[0] == key
中使用了这个条件。任何人都可以在这里为我提供一些见解
def __setitem__(self,key,value):
hash = self.get_hash(key)
found = False
#self.arr[hash]= value#adds the value of the key to the array[hash]
for idx,element in enumerate(self.arr[hash]): #iterate over the loop
if len(element) == 2 and element[0] == key:
self.arr[hash][idx] = (key,value)
found = True
print("index: "+idx+"element: "+element)
break
if not found:
self.arr[hash].append((key,value))
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。