Good afternoon! I was wondering if anyone might provide some insight into the issue I patched up near the end of my for loop. For some reason I kept getting an error saying: Oops, try again. Your function fails on censor("hey hey hey","hey"). It returns " *** *** *** " when it should return "*** *** ***".
I interpret this to mean something in my if statement was placing a space before the first word in my string, but I can't figure out why I kept having this issue and no one else seemed to. As you can see, I fixed it using the .lstrip() command, but I wanted to know if anyone had any suggestions for a more elegant solution.
def censor(text, word): text = text.split() print text count = len(word) new_text = '' for index in text: if index == word: new_text = new_text + " " + ("*" * count) else: new_text = new_text + " " + index return new_text.lstrip(" ") print censor("hey hey hey", "hey")