Question
Insert method for hashtable class HashTable: def __init__(self): self._content = [[], [], [], []] def get_hash(self, key): if key == '': return 3 return ord(key[0])
Insert method for hashtable
class HashTable: def __init__(self): self._content = [[], [], [], []] def get_hash(self, key): if key == '': return 3 return ord(key[0]) * len(key) def insert(self, key, value): """ Insert (key, value) into this HashTable using self.get_hash() as the hash function. """ pass
Example:
h = HashTable() h.insert('a', 'b') print(h)
0: [] 1: [('a', 'b')] 2: [] 3: []
More examples:
if __name__ == '__main__': ht = HashTable() ht.insert('a', 'b')
>>> 0: [] 1: [('a', 'b')] 2: [] 3: []
ht.insert('apple', 'bee') "0: [] 1: [('a', 'b'), ('apple', 'bee')] 2: [] 3: []"
ht.insert('apple', 'juice') "0: [] 1: [('a', 'b'), ('apple', 'juice')] 2: [] 3: []"
ht.insert('d', 'cat') ("0: [('d', 'cat')] 1: [('a', 'b'), " + "('apple', 'juice')] 2: [] 3: []")
ht.insert('yes', 'no') ("0: [('d', 'cat')] 1: [('a', 'b'), " + "('apple', 'juice')] 2: [] 3: [('yes', 'no')]")
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started