Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

Part 1 import string def stripStrs for whitespace in stringwhitespace removes all whitespaces from s... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Java Concepts Late Objects

Authors: Cay S. Horstmann

3rd Edition

1119186714, 978-1119186717

More Books

Students also viewed these Programming questions

Question

What is the this reference? Why would you use it?

Answered: 1 week ago