Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

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

Database 101

Authors: Guy Kawasaki

1st Edition

0938151525, 978-0938151524

More Books

Students also viewed these Databases questions

Question

Identify the ritualized aspects of football that advertising uses.

Answered: 1 week ago

Question

Define the placebo effect and describe what it tells us.

Answered: 1 week ago