← Back to challenges

Censor Words from List

PythonHardstringslanguage_fundamentalsformatting

Instructions

Create a function that takes a string txt and censors any word from a given list lst. The text removed must be replaced by the given character char.

Examples

censor_string("Today is a Wednesday!", ["Today", "a"], "-") ➞ "----- is - Wednesday!"

censor_string("The cow jumped over the moon.", ["cow", "over"], "*"), "The *** jumped **** the moon.")

censor_string("Why did the chicken cross the road?", ["Did", "chicken", "road"], "*") ➞ "Why *** the ******* cross the ****?"

Notes

N/A

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.