Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that reads in the contents of a text file and displays a histogram of the frequency that words appear in the text.

Write a program that reads in the contents of a text file and displays a histogram of the frequency that words appear in the text. Requirements: - Prompt the user to enter the filename of a text file - Read the contents of that text file and count the number of times each word appears in the file - Store the words and associated counts in a dictionary as key-value pairs - Display a histogram using asterisks representing the frequency that the words in the file appear Notes: Make the program case-insensitive (so The is considered the same word as the), and punctuation marks should be replaced with spaces prior to counting the words. See example below, which can be incorporated into your program:

s = "Python is great. Python is useful. Python is fun. Really fun!"

punctuation = [',',';','.',':','!',"'","\""]

for ch in punctuation:

s = s.replace(ch,' ')

s = s.split())

Sample run (example.txt contains the string s in the above code example):

Enter the filename: example.txt

Word Frequency

--------------

python: ***

is: ***

great: *

useful: *

fun: **

really: *

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

2nd Edition

1597499471, 978-1597499477

More Books

Students also viewed these Databases questions

Question

4. In my mind, I can visualize clear, precise, sharp images.

Answered: 1 week ago

Question

What are the benefits of planning for growth?

Answered: 1 week ago