Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In part 2 you are going to create word count statistics for a book. Your program will process all of the lines in a book
In part 2 you are going to create word count statistics for a book. Your program will process all of the lines in a book and provide a summary report about the different words in the book.
Clean the words before doing any processing on them:
- Remove leading and trailing whitespace on each word (use the strip() function),
- Remove the characters ,.!?'": (use the replace() function),
- Compare the words in a case-insensitive way (use the lower() function or the casefold() function)
Track the frequency of all the words in the books. Print out the following statistics:
- Total number of words in the book
- Number of unique words in the book (words that appear only once)
- Number of distinct words in the book (all words without duplication)
- Most used word out of all words in the book (the word that appears most frequently)
Sample output for frankenstein.txt:
What's the name of the book? frankenstein.txt Summarizing [frankenstein.txt] There are 76581 total words. There are 3961 unique words. There are 8187 distinct words. Most word used is [the] with 4241 uses Programmed by the Instructors Date: Tue Feb 5 11:33:05 2019 End of processing
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