Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Visual Basic Net Database Programming

Authors: Rod Stephens

1st Edition

0789726815, 978-0789726810

More Books

Students also viewed these Databases questions

Question

describe the main employment rights as stated in the law

Answered: 1 week ago