Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Database Fundamentals Study Guide

Authors: Dr. Sergio Pisano

1st Edition

B09K1WW84J, 979-8985115307

More Books

Students also viewed these Databases questions