Question: Write a function called generate?frequency?table?ilename) which accepts the name of a text file and returns a dictionary containing the frequency of all the letters that

Write a function called generate?frequency?table?ilename) which accepts the name of a text file and returns a dictionary containing the frequency of all the letters that appear in the file. For purposes of the frequency count, any non-letter characters are ignored, and the difference between upper and lower case letters is ignored (i.e., treat all letters as lower case).

You may wish to break the task up further and use several smaller functions to achieve this task. For example, it might be convenient to have functions to perform each of the following tasks:

? Read and return the contents of a text file

? Remove all non-letter characters from a given string

? Perform a frequency count of letters in a given string

The string class has an attribute called ascii_letters which is a string containing all the letters. You can access that string using:

import string letters = string.ascii_letters https://coderunner2.auckland.ac.nz/moodle/pluginfile.php/29330/question/questiontext/120411/7/25822/test_01.txt https://coderunner2.auckland.ac.nz/moodle/pluginfile.php/29330/question/questiontext/120411/7/25822/test_02.txt For example: Test data print

import string letters = string.ascii_letters https://coderunner2.auckland.ac.nz/moodle/pluginfile.php/29330/question/questiontext/120411/7/25822/test_01.txt https://coderunner2.auckland.ac.nz/moodle/pluginfile.php/29330/question/questiontext/120411/7/25822/test_02.txt For example: Test data print (data generate_frequency_table('test_01.txt') {'a': 2, 's': 1, 'm': 1, '1': 3, 't': 2, 'e': 2, 'x': 1, 'f': 1, 'i': 1}) generate_frequency_table('test_02.txt') data = print(data {'a': 4, 's': 3, 'm': 1, '1': 5, 't': 5, 'e': 4, 'x': 1, 'f': 1, 'i': 3, 'h': 4, 'o': 3, 'n': 3, 'p': 1, 'u': 2, 'c': 1}) == Result Tr ue Tr ue

Step by Step Solution

3.50 Rating (153 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To solve this problem we can create a function called generatefrequencytable that reads a file proce... View full answer

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 Programming Questions!