Practice Makes Perfect: Censor
I've gotten it to replace the words with asterisks, but when I split the string it is removing the spaces between words and I can't figure out how to get them back in:
Oops, try again. Your function fails on censor("hey hey hey","hey"). It returns "******" when it should return " *** ***".
def censor(text, word): text=text.split() length=len(word) new_text="" for x in text: if x==word: x="*"*length new_text+=x else: new_text+=x return new_text print censor("hey hey hey","hey")