Practice Makes Perfect_censor


#1

ERROR:
Oops, try again. Your function fails on censor("hey hey hey","hey"). It returns "['h', 'e', 'y', ' ', 'h', 'e', 'y', ' ', 'h', 'e', 'y']" when it should return "*** *** ***".

Please help.

def censor(text,word):
newword=[]
s=len(word)
for phrase in text :
if phrase==word:
phrase=''s
else:
flag=True
newword.append(phrase)
return newword


#2

here:

for phrase in text :
    if phrase==word:

looping like this will give you each individual letter, a single letter can't equal a word


#3

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