Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The purpose of this question is to write a complete Python program that computes the frequencies of letters in the words from a list of

image text in transcribed

The purpose of this question is to write a complete Python program that computes the frequencies of letters in the words from a list of words. Include the following function in your program. def getWords # words - a list of strings created from one string The text given below is copyrighted but is free for you to use as described in the Creative Commons License. words = '''THE SPECIAL THEORY OF RELATIVITY PHYSICAL MEANING OF GEOMETRICAL PROPOSITIONS In your schooldays most of you who read this book made acquaintance with the noble building of Euclid's geometry, and you remember -- perhaps with more respect then love -- the magnificent structure, on the lofty staircase, of which you were chased about for uncounted hours by teachers. By reason of our past experience, you would certainly regard everyone with who should pronounce even the most out-of-the-way proposition of this science to be on true. But perhaps this feeling of proud certainty would leave you immediately if someone were to ask you: "What, then, do you mean by the assertion that these propositions are true?" Let us proceed to give this question a little consideration, ''', split|) return words Write a function that begins with the following header: def letterFrequencies (words): This function is given: words - the list of words for which the letter frequencies are to be computed Create a dictionary named frequencies. The key in frequencies is a lowercase letter. The data value is the number of times (frequency) that letter occurs in the list of words. For each word from the list of words convert the letters to lowercase. For each character in a lowercase word determine if the character is a letter. If the character is a letter determine if the letter is in frequencies. If the letter is in frequencies add 1 to the corresponding data value. Otherwise create a new element in frequencies where the letter is the key and the data value is 1. Once all of the letters of all of the words have been counted create a second dictionary named reverseFrequencies where the key is the frequency of a letter and the data value is the letter. Use the information in frequencies to add elements to reverseFrequencies. Return frequencies followed by reverseFrequencies. Write a function that begins with the following header: def displayFrequencies [frequencies, descending=False): The function is given: frequencies - a dictionary of letters and frequencies descending - indicates whether or not the keys should be sorted in descending order (False means sort in ascending order, True means sort in descending order) Print a heading as shown in the sample run of the program. Use the sorted function to sort the keys of the dictionary. The second argument to sorted must be reverse=descending. For each of the sorted keys print the key and the data value, one pair of values per line. The key is in 3 character positions and the data value is in 4 characters positions. As the key and data values can be either str or int use a could that can convert either a str or int to a string. Write a function that begins with the following header: def main(): This function: prints a line of dashes calls getWords to get the list of words calls letterFrequencies to get the two dictionaries calls displayFrequencies to display the dictionary of frequencies calls displayFrequencies to display the disctionary of reverseFrequencies, specifying that the keys must be sorted in descending order calls displayTerminationMessage to display the termination message

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_2

Step: 3

blur-text-image_3

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

Graph Databases

Authors: Ian Robinson, Jim Webber, Emil Eifrem

1st Edition

1449356265, 978-1449356262

More Books

Students also viewed these Databases questions

Question

How is vacation and sick time accrued?

Answered: 1 week ago

Question

=+ Does the job incumbent work outside or in an office setting?

Answered: 1 week ago

Question

What do Dimensions represent in OLAP Cubes?

Answered: 1 week ago