Question
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
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