10/15 Censor is not working


#1

Hi, Guys
Why my code is not working? seems everything ok, but showing message
Oops, try again. Your function fails on censor("hey hey hey","hey"). It returns "*** *** *** " when it should return "*** *** ***".

def censor(text, word):
listtext=[]
wordlist=[]
i=0
b=0
while i if text[i]==" " :
print len(listtext)
listtext.append(text[b:i])
b=len(text)-len(text[i+1:])
i+=1
listtext.append(text[b:i])
p=0
for x in listtext:
if word==x:
listtext[p]=''len(word)
p+=1
result=''
for u in listtext:
result+=u+" "
return result


#2

Hey,

In your function you set result = ", but since the code runs maybe the missing " is just cut off from your original code. When you concatenate result with result += u + " " you add a space after everyword, but you shouldn't add one after the last word.

Also your code is a bit hard to read, maybe you should use the split() method introduced earlier in the course to write a more simple program.


#3

actually, you should split the original sentence into a list using the APPEND function.
then, create a new list which runs using the if...or relationship.
finally, print a string using the JOIN function.