Hi, I am having issues with this section of the course as well. I keep refining my code and this is as close as I can get, and it appears to censor the right words, but it appends them to the end of the string without putting them back in their original places. Could you suggest what I can do?

def censor(text, word):
    product = []
    new_txt = text.split(" ")
    for i in new_txt:
        if i == word:
            new_word = "*" * len(word)
    return " ".join(product)

I get the following error: > Oops, try again. Your function fails on censor("Yo go fro yo go","go"). It returns "Yo fro yo ** **" when it should return "Yo ** fro yo **".


look at this two lines:


you are appending to two different lists, why? There are two common ways to solve this problem:

  1. replace the words which require censoring in new_text
  2. append uncensored and censored word to new list

you seem to choice the second approach, but this means you have to append new_word to new_text


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