Censor not working


I'm not sure how to link the exercise, but the instructions are:

Write a function called censor that takes two strings, text and word, as input. It should return the text with the word you chose replaced with asterisks.

Unfortunately it gives the error:

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

Why does my code not replace the second go in that sentence?

def censor(text, word):
    words = text.split()
    l = len(word)
    for i in range(l):
        if words[i] == word:
            words[i] = "*" * l
    return ' '.join(words)


your for loop:

for i in range(l):

l contains the length of the word you want to censor, this should be the length of words (since you want to loop over all words/the sentence)

since you loop over the length of go it is not enough to loop over all words in the words list


Why thank you. I have no idea why I missed something so simple.