Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Problem 3 - letters.py Write a Python function count _ letters ( file ) for counting letters in a text file. Input: name of file
Problem letters.py
Write a Python function countlettersfile for counting letters in a text file.
Input: name of file relative to the present working directory pwd see below eg countlettersfrosttxt 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.asciilowercase
Ignore case; eg consider 'Treat' as having ts instead of T and t
Reading files You can use open to open a file. It creates an iterator that goes through the file, line
by line. The example below shows how to iterate over the provided file frost.txt printing every line:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started