Editor

Censor Banned Words

#247 · Strings · Beginner · 40 XP · about 8 min

A comments section hides rude words by replacing each of their letters with an asterisk. Write censor(text, banned) that returns text with every banned word censored.

  • A word is a run of letters. Spaces and punctuation separate words.
  • A word is censored when it equals one of the words in banned, ignoring case. Only whole words count: if "ass" is banned, "class" stays as it is.
  • A censored word becomes the same number of * characters. Everything else in the text, spaces and punctuation included, stays exactly as it was.

banned is a list of lowercase words.

Examples

censor('What the heck, HECK!', ['heck'])
# returns 'What the ****, ****!'
censor('The class has a bass player', ['ass'])
# returns 'The class has a bass player'
censor("Darn. Drat! It's DRAT again", ['darn', 'drat'])
# returns "****. ****! It's **** again"

Note

Texts contain only English letters, spaces and punctuation marks (no digits or underscores).

Fastest solvers

Leaderboard

First solves only, ranked by stars and then time.