10. Censor



When I attempt to run the code, it throws the following error message:

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

I don't understand why this does not work, as the output is exactly what I have expected, "There's a lot of *** in *** sentences"

censoredlst = ["stuff", "other"]

def censor(text,word):
    newsentence= ""
    sentencelst = text.split(" ")
#    print sentencelst
    for w in sentencelst:
      #  print word
        if w in word:
            newsentence+=  "*" * 3 + " " 
            newsentence+= w + " "
    return newsentence

sentence = ("There's a lot of stuff in other sentences")
print censor(sentence,censoredlst)

I would greatly appreciate any responses! Thank you in advance


you have an additional space at the end of the sentence:


i replaced the spaces with underscores so you can see it


I understand. I didn't actually realize that, haha. Thank you!