Answered step by step
Verified Expert Solution
Link Copied!

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 3- letters.py
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. 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

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2010 Barcelona Spain September 2010 Proceedings Part 2 Lnai 6322

Authors: Jose L. Balcazar ,Francesco Bonchi ,Aristides Gionis ,Michele Sebag

2010th Edition

364215882X, 978-3642158827

More Books

Students also viewed these Databases questions