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:

>>> import string >>> print string.punctuation ! 

 

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

1 Expert Approved Answer
Step: 1 Unlock

Part 1 import string def stripStrs for whitespace in stringwhitespace removes all whitespaces from s... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!