Question
Python Question: Write a program that will read the file, 'red-headed-league.txt', count the frequency of the words and store it as a csv file. Create
Python Question:
Write a program that will read the file, 'red-headed-league.txt', count the frequency of the words and store it as a csv file.
Create a class called WordCounter with the following methods.
def __init__(self,filename) where filename is the name of the text file, 'red-headed-league.txt'. This function should read the text file
def removepunctuation(self) must remove all the punctuations and leave only alphabets and numbers in each word
def findcount(self) must count the frequency of each word and store it in a instance variable called countdict
def writecountfile(self,csvfilename) writes the content of the countdict variable to a csv file with two columns. The first column is the word and second column is the count.
Create an instance of the class and call appropriate method and store the result in a csv file. Printout the five most popular words.
NOTE: DO NOT USE THE COUNTER DATA STRUCTURE IN COLLECTIONS MODULE.
- This question is related to Python ----------------------------------------------------------------------------
'red-headed-league.txt'
I had called upon my friend, Mr. Sherlock Holmes, one day in the autumn of last year and found him in deep conversation with a very stout, florid-faced, elderly gentleman with fiery red hair. With an apology for my intrusion, I was about to withdraw when Holmes pulled me abruptly into the room and closed the door behind me.
"You could not possibly have come at a better time, my dear Watson," he said cordially.
"I was afraid that you were engaged."
"So I am. Very much so."
"Then I can wait in the next room."
"Not at all. This gentleman, Mr. Wilson, has been my partner and helper in many of my most successful cases, and I have no doubt that he will be of the utmost use to me in yours also." The stout gentleman half rose from his chair and gave a bob of greeting, with a quick little questioning glance from his small fat-encircled eyes.
"Try the settee," said Holmes, relapsing into his armchair and putting his fingertips together, as was his custom when in judicial moods. "I know, my dear Watson, that you share my love of all that is bizarre and outside the conventions and humdrum routine of everyday life. You have shown your relish for it by the enthusiasm which has prompted you to chronicle, and, if you will excuse my saying so, somewhat to embellish so many of my own little adventures."
"Your cases have indeed been of the greatest interest to me," I observed.
"You will remember that I remarked the other day, just before we went into the very simple problem presented by Miss Mary Sutherland, that for strange effects and extraordinary combinations we must go to life itself, which is always far more daring than any effort of the imagination."
"A proposition which I took the liberty of doubting."
"You did, Doctor, but none the less you must come round to my view, for otherwise I shall keep on piling fact upon fact on you until your reason breaks down under them and acknowledges me to be right. Now, Mr. Jabez Wilson here has been good enough to call upon me this morning, and to begin a narrative which promises to be one of the most singular which I have listened to for some time. You have heard me remark that the strangest and most unique things are very often connected not with the larger but with the smaller crimes, and occasionally, indeed, where there is room for doubt whether any positive crime has been committed. As far as I have heard it is impossible for me to say whether the present case is an instance of crime or not, but the course of events is certainly among the most singular that I have ever listened to. Perhaps, Mr. Wilson, you would have the great kindness to recommence your narrative. I ask you not merely because my friend Dr. Watson has not heard the opening part but also because the peculiar nature of the story makes me anxious to have every possible detail from your lips. As a rule, when I have heard some slight indication of the course of events, I am able to guide myself by the thousands of other similar cases which occur to my memory. In the present instance I am forced to admit that the facts are, to the best of my belief, unique."
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started