Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In PYTHON PLEASE Write a program that takes as input a text file of arbitrary length and count the occurrence of words in that text.

In PYTHON PLEASE

Write a program that takes as input a text file of arbitrary length and count the occurrence of words in that text. Present the counts and words, sorted with the highest count first, and remove punctuation and change all words to lowercase. Also remove stopwords. Follow these steps:

implement the starter program. You need to comment the program. Read the code. Figure out how it works.

a file of stopwords for you to use called stopWordsEng.txt. read the file and omit these words from the word counts made in the program.

Starter program:

def byFreq(pair): return pair[1] def main(): print("This program analyzes word frequency in a file") print("and prints a report on the n most frequent words. ") # get the sequence of words from the file fname = input("File to analyze: ") text = open(fname,'r').read() text = text.lower() for ch in '!"#$%&()*+,-./:;<=>?@[\\]^_`{|}~': text = text.replace(ch, ' ') words = text.split() #  counts = {} for w in words: counts[w] = counts.get(w,0) + 1 #  n = int(input("Output analysis of how many words? ")) # Print your output here. The command below is a placeholder # to get you started, but it is not the final solution! print(counts) main()

stopwords file:

it is a file with words like i me my myself we our ours ourselves you your yours yourself yourselves he him his himself she her hers herself it its itself they them their theirs themselves what which who whom, etc

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

Step: 3

blur-text-image

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

Pro SQL Server Administration

Authors: Peter Carter

1st Edition

1484207106, 9781484207109

More Books

Students also viewed these Databases questions