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

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!