10.censor: Possible without splitting the string?



I know the hint suggests splitting the string into a list to cycle through each word individually. I've been trying to solve it without splitting anyway, but with no success. Apparently my code does absolutely nothing, since I get the following error message:

"Oops, try again. Your function fails on censor("hey hey hey","hey"). It returns "hey hey hey" when it should return "*** *** ***"."

Any tips, or should I just try splitting the string?

def censor(text,word):
    if word in text:
        text.replace(word, "*"*(len(word)))
    return text


the replace function does not modify the original string in memory but rather create a new modified string and returns it. you need to store it in a variable and return that variable


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.