Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This problem requires you to prompt the user for a sentence and then construct two lists: one that contains each unique word, and one that
This problem requires you to prompt the user for a sentence and then construct two lists: one that contains each unique word, and one that contains the number of times that word occurred in the sentence. Create these as parallel lists where the indices match between the lists. The index for the word in the words list should match the index for that words count in the occurrences list. This problem will have you practice with strings, lists, and loops.
The input prompt should be as follows:
"Enter your sentence:
You will need to remove any punctuation from the sentence. As a simplification, you can assume that any punctuation will be at the beginning or end of a word, and you only need to worry about the characters Extra spaces should also be removed.
You will also need to make sure that all of the words are converted to lower case for purposes of counting their frequency and the final list.
Hint: There is punctuation in the middle of the sentence such as commas. These will need to be removed. It can be useful to split up the string to then process each word in the sentence to remove punctuation.
For example, if the user entered the sentence "The cow jumped over the moon.", your program would create two lists to keep track of the words and the word occurrences. After calculating the word frequencies, print out the words as well as their frequencies in the following format:
Word.........Frequency
the.................
cow.................
jumped..............
over................
moon................
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