Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

***Python 3.6*** 3. For this problem, you'll be going back to the histogram functions from problem #1. Add the tollowing functions to char_hist3.py a. Define

***Python 3.6***

image text in transcribed

3. For this problem, you'll be going back to the histogram functions from problem #1. Add the tollowing functions to char_hist3.py a. Define a function file to hist() which takes a string representing a filename, opens the file, reads its contents, closes the file,* and returns a histogram based on the letter frequencies in the given file. If no such file exists, it's okay if the function crashes. So for example, if the file cow.txt was in the same directory as char_hist3.py and had the following contents I have never seen a purple cow, And I never hope to see one. But l can tell you anynow I'd rather see than be one Then file_to_hist("cow.txt") would return the following histogram:'r': 5, 'w' 2. 't':5,' 2, 'u': 3, "o7 B':1, "b': 1, "p': 3, 's': 3, "d *Remember to close the file before returning the histogram. b. Finally, to show off your results, go to Project Gutenberg, and download the plain text version of your favorite* work of literature. Save the file to the same directory as char hist3.py, and use the functions you wrote to draw an ordered histogram of the character frequencies in the file. Save a transcript lab8-transcript.py that includes this histogram and attach that to your Canvas submission. Don't use anything longer than a single novel or Python will use up a lot of memory on your computer, causing it to slow down or possibly even crash. For my example, I've chosen the book Flatland, by Edwin A. Abbott. I'm not showing you the command I used, but here's the resulting histogram, sorted by key

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

Students also viewed these Databases questions

Question

What do you think of the MBO program developed by Drucker?

Answered: 1 week ago