Censor


#1



https://www.codecademy.com/courses/python-intermediate-en-rCQKw/1/4

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


def censor(text,word):
    text1=text.split(" ")
    res=""
    for i in text1:
       if i==word:
            res=res+" "+("*" * len(word))
       else:
            res=res+" "+i
            
              
    return res


#2

Appending white space can lead to an incorrect string being returned. The alternative is to build a list with only the words (or the substitution) and insert white space in the join() to create the return string.