Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Use Python Complete the recoverMessage) function, which takes a list of equal-length strings as its single argument. You may assume that each string ONLY contains
Use Python
Complete the recoverMessage) function, which takes a list of equal-length strings as its single argument. You may assume that each string ONLY contains lowercase letters; there are no spaces, digits, uppercase letters, or punctuation symbols in any of the source strings The function returns a single string whose length is equal to that of any one of the source strings. This function works as follows: 1. Create a dictionary that will hold the frequency of each letter (you can either pre-populate this with all 26 letters, or you can simply create an empty dictionary and use the setdefault ) function to add new letters to the dictionary as you encounter them) 2. Create a variable to hold the recovered string (this will initially be the empty string) 3. For each index value: (a) Examine the letter at that index in each source string. Update the dictionary's count for that letter(i.e., if you see a(nother) "b", add 1 to the integer value associated with the key "b" in your dictionary) (b) When you have evaluated all of the source strings at the given index, determine which dictionary key (letter) has the largest value associated with it (for each key in your dictionary, examine its value and compare it to the largest value that you've seen so far). Here is pseudocode for one possible sub-algorithm most-common = value of index 0 from your dictionary's list of keys for each key k in your dictionary if k's value is greater than the value associated with most_common: set most common to k Append that letter to your "recovered string" variable. For example, given the dictionary {"a":3, "b":5, "c":4) your code would return "b" as the most frequent letter. If two or more letters tie for the highest frequency in a given position, you may select any one of them as the "winner"; we will ultimately use context and human intuition to determine what the correct letter should have been (c) Clear or reset the contents of the dictionary in preparation for the next round of your loop 4. When the outermost loop ends, return the value of your recovered string Examples: Function Call recoverMessage (["edferfthm", "aqvorithm", "algbridnn", algorithm "glgoxirhm", "iogleielb", "alwxuithj", "wlaobifhm"] ) Return ValueStep 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