Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 image text in transcribed
image text in transcribed
image text in transcribed
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

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 Development For Dummies

Authors: Allen G. Taylor

1st Edition

978-0764507526

More Books

Students also viewed these Databases questions