def censor(text,word): text_list= text.split() new =  print (text_list) for c in text_list: if c in word: new.append("*") else: new.append(c) print (c) "".join(new) return new censor("test","es")
Can anyone tell me why this doesn't work? I don't understand why not? I split me text in a new variable and for every element in the list I check if it matches any substring of word. If so, replace with a * and append. If not append original character. The result is:
Your function fails on censor("hey hey hey","hey"). It returns "['', '', '*']" when it should return "*** *** ***".
It seems like my text is not split up but looking at the examples on the forum here makes me believe I have made no mistake. Apparently I have. Help?