10/15 Censor: Only processes first word!


#1

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):
  text.lower()
  stext = text.split()
  newtext = []
  for t in stext:
   if t == word:
      newtext.append("*" * len(word))
   else:
      newtext.append(t)
  return newtext
print censor("jimmy rocks", "rocks")


#2

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


#3

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


#4

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


#5

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.


#6

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

return " ".join(newtext)

#7

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


#8

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