Question: (This problem is a continuation of Assignment 2. Problem 5.) Write a function censor2 which takes as input a string text and a list of

 (This problem is a continuation of Assignment 2. Problem 5.) Write

(This problem is a continuation of Assignment 2. Problem 5.) Write a function censor2 which takes as input a string text and a list of strings banned. Your function should retum a string which is obtained from text by replacing each occurrence of any string from banned in text by the string consisting of the same numbers of astorisks). In contrast to (and improving upon) the function censor from Assignment 2, your function censor2 should consor words irrespective of capitalisation For example: censor('This is appaling and outrageous. L'appaling', outrageous'1) should return "This is ******** and **********.' (Just like censor.) censor2('I strongly DISLIKE this problem.', 'dislike', 'hate') should return 'I strongly ******* this problem. censor2('Cats and dogs!', 'cat', 'dog'l) should return *** and ****!". Note. You may again assume that no string in banned occurs as a substring of any other string in banned In 1 1: def censor2(text, banned): In 1 1: assert censor2('This is appaling and outrageous.', l'appaling', 'outrageous! 1) - This is ******** and ********** In 1: assert censor2t'I strongly DISLIKE this problem. I'dislike', 'hate']) == 'I strongly ***** this problem. In I : assert censor2("Cats and dogs!', ['cat', 'dog'l) =****s and ****! In [ 1

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!