Build a Hash Table - Build a Hash Table

Tell us what’s happening:

i am unable to move forward as a constant error mentioning that there is something wrong with my code pops up however i don’t understand what is wrong with my code .

I have tried refreshing the page multiple times

image

also test 10 and 15 I’m unable to pass if i could get some help please

Your code so far

class HashTable:
    def __init__(self):
        self.collection = {}
    
    def hash(self,word):
        sum_of_unicode = 0
        for letter in word:
            sum_of_unicode += ord(letter)
        return sum_of_unicode
    
    def add(self,key,value):
        hash_key = self.hash(key)
        if hash_key in self.collection:
            self.collection[hash_key][key]=value
        else:
            self.collection[hash_key] = {}

    def remove(self,key):
        hash_key = self.hash(key)
        if hash_key in self.collection:
            if key in self.collection[key_hash]:
                del self.collection[key_hash][key]
        return
    
    def lookup(self,key):
        hash_key = self.hash(key)
        if hash_key in self.collection:
            return self.collection[hash_key]
        else:
            return None

print(HashTable().hash('golf'))
print(HashTable().collection)
print(HashTable().add('golf', 'sport'))
print(HashTable().add('read', 'book'))
print(HashTable().add('dear', 'friend'))
print(HashTable().lookup('golf'))
print(HashTable().collection)

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36

Challenge Information:

Build a Hash Table - Build a Hash Table

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/lab-hash-table/67ed03ac474c48692f41749e.md at main · freeCodeCamp/freeCodeCamp · GitHub

Hi @samy_questions

10. When you try to remove a key that does not exist in the collection, it should not raise an error or remove anything.

Test 10 is for the remove function.

You define:

You reference:

Happy coding