Question: pass the few test by using python thanks The problem with our previous code is that we require an exact case match: if we have

pass the few test by using python thanks  pass the few test by using python thanks The problem with
our previous code is that we require an exact case match: if
we have the string: Does are nice" and a replacement dictionary the

The problem with our previous code is that we require an exact case match: if we have the string: Does are nice" and a replacement dictionary the result of replace_once(t, d) is still Dogs are nice". Write a function repince_case_intensitive t. d) that applies the replacement irrespective of whether the original word is capitalized or not, and that preserves the capitalization, a capitalized word is replaced with another capitalized word. For example, if d = dog" "cat7 then replace_case_insensitive Dogt are nice", dis: and replace_case_insensitivet til dono d) is: When writing your solution, you can assume that both keys and values in the replacement dictionary appear in lowercase. Note also that you only need to concern yourselves with words that are either all in lowercase, like "dor", or capitalized, like Dox": you don't have to worry about words like "Doc" or "Doc de replace_case_insensitivelt, d): Sparat: string @param di dictionary, mapping words to their replacements Preturns: string where words in d have been replaced according to the dictionary mapping in case insensitive way, and preserving capitalization # YOUR CODE HERE t = "I love dogs" d = {"dogs": "cats") check_equal (replace_case_insensitive (t, d), "I love cats") t = "Dogs are nice 1 d = {"dogs": "cats") check_equal (replace_case_insensitive (t, d), "Cats are nice") = "Cats cats nothing else than cats" {"dogs": "cats","cats": "dogs"} check_equal (replace_case_insensitive (t, d). "Dogs dogs nothing else than dogs) t d t d BEGIN HIDDEN TESTS = "Cats and dogs are Dogs and cats = "dogs": "cats","cats": "dogs"} check_equal (replace_case_insensitive(t, d), "Dogs and cats END HIDDEN TESTS are Cats and dogs")

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!