Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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 Concepts International Edition

Authors: David M. Kroenke

6th Edition International Edition

0133098222, 978-0133098228

More Books

Students also viewed these Databases questions