10. Censor


#1



https://www.codecademy.com/courses/python-intermediate-en-rCQKw/1/4?curriculum_id=4f89dab3d788890003000096#

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 + " " 
        else:
            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


#2

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

***_***_***_

i replaced the spaces with underscores so you can see it


#3

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


#5