stuck with this error:

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

code is:

def censor(text, word):
p = []
t = text.split()
for f in t:
if word in t:
f = "*" * len(word)
p += f

Please help


Since you are working with two string arguments it woud be better to use an empty string here,


p = ""

Also because you are looping over a string don't loop over your already split text but use the full string and check if it is equal to a letter in the word you are censoring,

for f in text:
    if f  == word:

and inside that if statement all you need to do is add asterisks to your empty string based on the length of the word,

p += (len(word) * "*")


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