Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Pythonimage 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

Step: 3

blur-text-image

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 Publishing With Filemaker Pro On The Web

Authors: Maria Langer

1st Edition

0201696657, 978-0201696653

More Books

Students also viewed these Databases questions

Question

5. List the forces that shape a groups decisions

Answered: 1 week ago

Question

4. Identify how culture affects appropriate leadership behavior

Answered: 1 week ago