Question: I'm trying to implement an open-hashing hash table and implement a hashable object type, Birthday, that can be used as a key into the hash

I'm trying to implement an open-hashing hash table and implement a hashable object type, Birthday, that can be used as a key into the hash table in Python 3

I have to create a class called "Birthday" using the following:

Three attributes for birth day, birth month, birth year

A constructor method that accepts the day, month, and year as parameters.

A __str__ method to provide a string representation of the Birthday object.

A __hash__ method that returns an integer as the sum of of the day, month, and year, mod 12. So if day=1, month=11, year = 1990, then this method would return (1+11+1990)%12, which is 10.

An __eq__ method to test if two Birthday objects have the same attribute value.

I have to place the implementation in a module called Birthday.py and create a __main__ section where you test instantiating Birthday objects, printing them, and calling the __hash__ method.

I also have to create a main file that will create an empty hash table, read in a list of birthdays from the supplied bdaylist.txt file, for each birthday, create a Birthday object, and add the tuple (Birthday,i) to the appropriate list in the hash table, where "i" is the line number from the input file, output the total length of the list at each of the hash locations.

Since the Birthday object's hash function hashes to integers in the range [0,12), I need to create a hash table with 12 empty lists in it. Here's what I have so far for this:

hashtable = []

for i in range(12):

hashtable.append([])

Here is the sample output:

Hash location 0 has 10 elements in it Hash location 1 has 12 elements in it Hash location 2 has 8 elements in it Hash location 3 has 10 elements in it Hash location 4 has 5 elements in it Hash location 5 has 7 elements in it Hash location 6 has 7 elements in it Hash location 7 has 11 elements in it Hash location 8 has 4 elements in it Hash location 9 has 8 elements in it Hash location 10 has 8 elements in it Hash location 11 has 10 elements in it

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!