Censor: Can't Tell What's Wrong


#1



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


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)


#2

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


#4

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