Question: How can I implament a word counter from a very long text file ie: the script to Romeo and Juliet, in Python by using a

How can I implament a word counter from a very long text file ie: the script to Romeo and Juliet, in Python by using a hash table? For example, if the text was "I had a very very nice day" the table woudl read I:1, had:1, a:1, very:2, nice:1, day:1". we are not allowed to use the dictionary data set so I created a "node" class as below. While iterating over the text, if a new word pops up, the node "word:1" is added to the table, at the index table[hash(word)%len(table)]. If the word reoccurs in the text, the value of word increments by 1. To handle collisions I am using linear probing and am rehashing when when the table is full. We must have methods to insert a new word, delete from the hash table, clear the table completely, and calculate the load factor.

Any help is appreciated. Thanks!!

class Node: def __init__(self,key,value=1): self.k = key self.v = int(value)

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!