Question: ii : Write a python program that does the following: Create 3 functions with docstring: 1. letter_counts() takes a string as its argument and returns
ii : Write a python program that does the following: Create 3 functions with docstring: 1. letter_counts() takes a string as its argument and returns a dictionary of the letters as keys and frequency counts as values. 2. most_common_letter() takes a string as its argument and returns a list of the most common letter(s). This function should call letter_counts(). 3. string_count_histogram() takes a string as its argument and returns a list of the unique letters, with each letter being the repeated number of times it appears in the string. This list will then be printed one element per line (as a histogram). This function should call letter_counts(). The following code should be after the functions and inside the block if __name__ == '__main__': Assign a sentence of at least 15 characters into a constant string variable. Write 3 print statements with appropriate descriptions that use these functions to create output like the examples. Notes: Line 1 is sorted alphabetically and not printed as a dictionary Line 2 grammatically handles more than one result (appear vs. appears) Histogram is sorted alphabetically Example Output #1 The string being analyzed is: "WAS IT A RAT I SAW" 1. Letter counts: 'A': 4, 'I': 2, 'R': 1, 'S': 2, 'T': 2, 'W': 2 2. Most frequent letter 'A' appears 4 times. 3. Histogram: AAAA II R SS TT WW Example Output #2 The string being analyzed is: "WWWAS IT A RAT I SAW" 1. Letter counts: 'A': 4, 'I': 2, 'R': 1, 'S': 2, 'T': 2, 'W': 4 2. Most frequent letters: 'A', 'W' each appear 4 times. 3. Histogram: AAAA II R SS TT WWWW
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
