10.censor: Possible without splitting the string?


#1



https://www.codecademy.com/courses/python-intermediate-en-rCQKw/1/4?curriculum_id=4f89dab3d788890003000096#


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


#2

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


#3

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