Build a Hash Table - Build a Hash Table

Tell us what’s happening:

Everything works, except Test 10 fails even though the program works and deletes nothing and there are no errors.

Your code so far

class HashTable:
    def __init__(self):
        self.collection = {}
    def hash(self, key_string):
        new_hash = 0
        for letter in key_string:
            new_hash += int(ord(letter))
        return new_hash
    def add(self, key, value):
        key_hash = self.hash(key)
        if key_hash in self.collection.keys():
            self.collection[key_hash].update({key : value}) 
        else:
            self.collection[key_hash] = {key: value}
    def remove(self, key):
        key_hash = self.hash(key)
        if key_hash in self.collection:
            if len(self.collection[key_hash]) > 1:
                del self.collection[key_hash][key]
            else:
                del self.collection[key_hash]
        return
    def lookup(self, key):
        key_hash = self.hash(key)
        if key_hash in self.collection.keys() and list(self.collection[key_hash].keys())[0] == key:
            return self.collection[key_hash][key]
        else:
            return None
        
h = HashTable()
h.add('bird', 'pelican')
print(h.remove('dog'))


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.3 Safari/605.1.15 Ddg/26.3

Challenge Information:

Build a Hash Table - Build a Hash Table

Instead of only checking the first key in the nested dictionary, check if the key exists directly in it.
Also, verify the key exists in the nested dictionary before attempting to delete it.

That did the trick, thank you!

The weird thing is that no error was being shown.