10/15 censor. I need help


def censor(text, word):
for x in text.split():
for n in word.split():
if n == x:
return text.replace(x,"*"*len(n))

print censor(“hey hey hey”,“hey”)
print censor(“this hack is wack hack”, “is”)
print censor(“this hack is wack hack”, “hack”)

*** *** ***
th** hack ** wack hack
this **** is wack ****

error message is this.

Oops, try again. Your function fails on censor(“hey hey hey”,“hey”).
It returns “*** *** ***” when it should return *** hey hey

I research this error all day. but I don’t know…
I want to next step. help me.

thank you. it’s korean versison.


Hello @gigacoder05452,
Can you indent your code properly?


I solved myself.

def censor (text,word):
result = []
count = 0
for x in text.split():
if word in x:
if count == 0:
result.append("*" * len(word))
count += 1
return " ".join(result)

print censor(“hey hey hey”,“hey”)

why not used replace?

Another Sample is used replace…
Korean version is wierd.


replace() is dull, it allows for a single line solution. And look at line 8, this hack is wack hack gets censored to th** hack ** wack hack, this shouldn’t get partial censored

Also, the course you currently taking is in the old learning environment, which is no longer supported, please update to supported course:



This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.