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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!