Censor


#1



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


Hello, I'm receiving an error message that tells me my censor code is not functioning properly, but it doesn't give me a clue as to why. Can you help identify the error? Thanks!

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


def censor(text, word):
    words = text.split(" ")
    censored = ""
    
    for item in words:
        if item == word:
            censored.join("*" * len(item))
        else:
            censored.join(word)
    return censored


#2

Could you tell me what you think .join() does? (yes, i know what it does, but i want to hear it from you)


#3

Sure. I'm under the impression that it consolidates the things I am attempting to join together into a single string.


#4

"".join() is built in function to join a list into string. but in your case, censored is already a string


#5

you can use censored as a list instead of a string, append() the item each time and return it using the join function.


#6

Thanks very much to both of you!


#8