Weird error in Censor


I get the expected output on the terminal, however I get a very strange error message.

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

I am unsure where this additional text is coming from. Also, how messed up is my code? Is there a better way to go about this? Thank you very much in advance!

lst = []
def censor(text,word):
    n = text.split()
    for x in n:
        if x != word:
    return ' '.join(lst)

print censor("hey hey hey","hey")


the lst[] is outside the function... hence it is returning garbage...

hope this helps...



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