I am close to this solution. The line works correctly except for the fact that I cannot get the spaces in between words. The error message is:
Your function fails on censor("hey hey hey","hey"). It returns "******" when it should return " *** ***".
If I add a space to the "".join(s) statement, like " ".join(s) it will ad a space in between letters, not words. Adding a space in the concatenation will add an additional space to the end of the string which is also undesired and throws an error.
The print statements, as written print the following:
hey hey hey
['hey', 'hey', 'hey']
I am getting the correct number of asterisks. I just need to find a way to add a space in between words. Can anyone help?
def censor(text, word): str1 = text.split() str2 = "" print text print word print str1 for s in str1: if s == word: s = s.replace(s, "*" * len(s)) str2 = str2 + "".join(s) print str2 return str2 censor("hey hey hey", "hey")