Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Let's go back now to the simpler version of the problem, where we replace in case-sensitive way. Our original version of the code applies the

Let's go back now to the simpler version of the problem, where we replace in case-sensitive way. Our original version of the code applies the replacement only once. That is, if the dictionary d maps:

d = {"cats": "dogs", "dogs": "pigs"}

and our text is t = "I love cats", the function replace_once(t, d) applies the replacement only once, and we obtain

"I love dogs"

Now, you should write a function replace_chain, that keeps applying replacements until no more replacements can be applied, so that replace_chain(t, d) yields:

"I love pigs"

def replace_chain(t, d):

"""

@param t: a string

@param d: a dictionary, mapping words to their replacements

@returns: a string, where words in d have been replaced according to the dictionary mapping,

repeating the replacements until no replacement can be applied.

"""

# YOUR CODE HERE

raise NotImplementedError()

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

Graph Databases New Opportunities For Connected Data

Authors: Ian Robinson, Jim Webber, Emil Eifrem

2nd Edition

1491930896, 978-1491930892

More Books

Students also viewed these Databases questions

Question

Distinguish between sequential processing and parallel processing.

Answered: 1 week ago