Censor: Can't Tell What's Wrong



Getting error "Oops, try again. Your function fails on censor("hey hey hey","hey"). It returns "hey hey hey" when it should return "*** *** ***"."
So I'm obviously not doing something right

When I added "print i" after the for loop, it prints each str on a separate line. But instead of replacing i it just breaks right to the end. Help?

def censor(text, word):
    newtext = text.split()
    for i in newtext:
        if i == word:
            i = "*" * len(word)
    return " ".join(newtext)


using a for in loop will give you read only values from the list, changes made to it won't persist


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