10/15 Censor: Only processes first word!


I know this is silly, but the code below will only process the first word in the phrase and then it stops. What am I missing? It must be something little, but I can't figure it out!!!

def censor(text, word):
  stext = text.split()
  newtext = []
  for t in stext:
   if t == word:
      newtext.append("*" * len(word))
  return newtext
print censor("jimmy rocks", "rocks")


I can't get the indents to show--sorry about that. I do have all the right indents in there.


it is hard to determine where the error is without the indentation. try to re-post your code with the indentation .To do that all you have to do is this

put your code here


but I am pretty sure it is where you are calling your return newtext is causing the problem. Make sure it is outside the for loop


OK, I used the html for an empty space to get some indents in there. Can you take a look now?


OK, I did what you said and it now does process all words--thank you! But then here is the message I get: "Oops, try again.
Your function fails on censor("hey hey hey","hey"). It returns "['', '', '']" when it should return " *** ***".

So I still must be doing something wrong. How do I get rid of the commas and the square brackets? When I try, the code breaks completely and won't compile.


newtest is a list so you want to join all the elements together like this

return " ".join(newtext)


Try to use the post formatting technique that I Have shown in post 3


It worked!!!!!!! THANK YOU!