Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a function called letter_count(filename) that accepts a single parameter containing the name of a file. Your function should read the contents of the text

image text in transcribedimage text in transcribed

Write a function called letter_count(filename) that accepts a single parameter containing the name of a file. Your function should read the contents of the text file, and calculate the number of times each English letter appears in the file. The function should print a list of (character: count) pairs to the standard output. You may define additional "helper" functions as you wish. Any character that is not an English letter should be ignored. The case should be ignored (so both 'a' and 'A' count as the letter 'a). Report the output with lower case letters. The letters should be sorted into standard alphabetical order and should be printed in the format letter, then a space, then a colon, then a space, then the frequency. lf a letter is not present in the file, then it should not be printed. E.g. b : 3 d:2 A student who completes this exercise should be able to Read the contents of a text file Use a dictionary to store keys and values Sort dictionary keys . For example: Test Input Result letter_countC'test1.txt) Contents of 'test1.txt' A simple file with only one line e 4 f 1 i :4 1:4 n:3 o2 letter_count('test2.txt Contents of 'test2.txt' This e:3 file has h:2 five lines 1:2 n: s:3

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

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

4th Edition

0805360476, 978-0805360479

More Books

Students also viewed these Databases questions

Question

Evaluate v rms for N 2 gas at 298.15 K.

Answered: 1 week ago

Question

Is there a clear hierarchy of points in my outline?

Answered: 1 week ago