Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Principles Of Database Systems With Internet And Java Applications

Authors: Greg Riccardi

1st Edition

020161247X, 978-0201612479

More Books

Students also viewed these Databases questions

Question

What is the growth rate of GDP per capita?

Answered: 1 week ago