Question
Write a function censor2 which takes as input a string text and a list of strings banned. Your function should return a string which is
Write a function censor2 which takes as input a string text and a list of strings banned. Your function should return 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 asterisks (*). In contrast to (and improving upon) the function censor from Assignment 2, your function censor2should censor words irrespective of capitalisation.
For example:
-
censor2('This is appaling and outrageous.', ['appaling', 'outrageous']) 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']) should return '***s and ***s!'.
Note. You may again assume that no string in banned occurs as a substring of any other string in banned.
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