Question: IN PYTHON Write a program that takes as input a text file of arbitrary length and count the occurrence of words in that text. Present
IN PYTHON
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.
Implement the starter program. You may use it as a starting point. 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. You will need to read this file and omit these words from the word counts made in the program.
stater 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() Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
