Tell us what’s happening:
If key is not in self.collection[key_hash], the method doesn’t raise an error or remove anything, it just returns. I can’t figure out from the console.log messages why I’m not passing test 10.
Your code so far
class HashTable():
def __init__(self):
self.collection = {}
def hash(self, string):
hash_sum = 0
for char in string:
hash_sum += ord(char)
return hash_sum
def add(self, key, value):
key_hash = hash(key)
if key_hash not in self.collection:
self.collection[key_hash] = {}
self.collection[key_hash][key] = value
def remove(self, key):
key_hash = hash(key)
if key_hash in self.collection:
if key in self.collection[key_hash]:
del self.collection[key_hash][key]
return
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.1 Safari/605.1.15 Ddg/26.1
Challenge Information:
Build a Hash Table - Build a Hash Table