My code manages to censor the correct words with asterisks but for some reason I can't seem to get the spaces correct.
When I run this code I get the following error:
Oops, try again. Your function fails on censor("hey hey hey","hey"). It returns "******" when it should return " *** ***".
def censor(text,word): n_list = '' for i in text.split(): if i == word: n_list+='*' * len(word) ' '.join(n_list) if i != word: n_list+=i ' '.join(n_list) return n_list I tried putting adding a space after a word is replaced by an asterisk by changing the line to : n_list+='*' * len(word) + ' ' This however leaves me with an extra space once the last word has been replaced.