Brainlag
  1. Library
  2. Challenges
  3. Python

A chat filter

Hide banned words in a game chat message with stars, whatever their capital letters, and leave every other word alone.

PythonCore20 min

Write clean(message, banned). message is a chat line with words separated by single spaces. banned is a list of lower case words. Return the message with every banned word replaced by stars, one star per letter. Match whole words only, and ignore capitals: "NOOB" is banned if "noob" is. Every other word stays exactly as it was.

Python
clean("you are a noob lol", ["noob"])    # "you are a **** lol"

Checks

  1. Banned words become stars
  2. Capitals and whole words
exercise_1.py to run
def clean(message, banned):
    pass

Code editor. Press Control or Command plus Enter to run the code. Tab indents; to move focus out of the editor, press Escape and then Tab.