Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a function called generate_frequency_table(filename) 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(filename) 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 Hint: The string class has an attribute called asci_letters which is a string containing all the letters. You can access that string using: import string letters -string.ascii_letters For example: Test Result data -generate_frequency_table('test 01.txt') print data'a': 2, 's': 1, 'm': 1, 'l': 3, 't': 2, 'e': 2, 'x": 1, 'f': 1,'ue i: 13) Tr data - generate_frequency_tableC'test_02.txt') print(data'a 4, 's': 3, 'm': 1, 'l': 5, 't': 5, 'e: 4, 'x': 1, 'f': 1, ' Tr ue
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