Question: Write a Python function count _ letters ( file ) for counting letters in a text file. Input: name of file relative to the present

Write a Python function count_letters(file) for counting letters in a text file.
Input: name of file relative to the present working directory pwd (see below), e.g. count_letters('frost.txt') if 'frost.txt' is in the pwd
Output: return the dictionary of letter:count pairs. Only include letters present in the file.
Use a dictionary to hold a mapping between a letter and its number of occurrences.
Ignore characters and symbols that are not standard ascii characters (only use characters that appear in string.ascii_lowercase)
Ignore case; e.g. consider 'Treat' as having 2't's instead of 1 T and 1 t.
Reading files - You can use open to open a file. It creates an iterator that goes through the file, line by line.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!