Question
Write a program that takes a string as input, strips whitespace and punctuation from the words, and converts them to lowercase. Hint: The string module
Write a program that takes a string as input, strips whitespace and punctuation from the words, and converts them to lowercase.
Hint: The string module provides strings named whitespace, which contains space, tab, newline, etc., and punctuation which contains the punctuation characters. Let’s see if we can make Python swear:
Part 2. Modify the program from part 1 above to count the total number of words in the string, and the number of times each word is used. Use a dictionary to store the frequency of each word. Your data structure should look something like:
>>> import string >>> print string.punctuation ! " # $ % & '()*+,-./:; ?@[\]^_^ {|}~\
Step by Step Solution
3.46 Rating (175 Votes )
There are 3 Steps involved in it
Step: 1
Part 1 import string def stripStrs for whitespace in stringwhitespace removes all whitespaces from s...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