Question: 5a. (10 pts) Write a function named decrypt, which takes a string s and a dictionary d where each key in the dictionary is a

5a. (10 pts) Write a function named decrypt, which takes a string s and a dictionary d where each key in the dictionary is a string word associated with a secret code as its key. This function should return the list of all possible ways (order it returns it in doesn't matter) in which the string s can be decoded by splitting it into secret codes and separating the corresponding words of the decoded word with spaces. For instance, calling decrypt('turing, 'turing': 'A', 'tur': 'B', 'ng 'C', 'tu': 'D', 'ring': 'E', 'ri': 'F' ng': G)) returns 'A, D E, D F G', B c']. These results are computed by first starting with the whole string 'turing', which has a corresponding secret code. Then consider substrings 't' and 'uring, which don't have any secret codes, and then , tu, and ring', etc. Note that the the substrings 'tu' and 'ring' produce 'D E', but also produces D F G' since there is an alternative decoding for 'ring' by splitting it up into the substrings 'ri' and 'ng' Accomplishing this can easily be done via recursion. There are no restrictions in how you write this function you may use any combination of loops, variables, lists, as desired. Of course, you will find it necessary to use recursion. def decrypt(s: str, d: (str: str) - [str]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
