Your function fails on censor("hey hey hey","hey"). It returns "hey hey hey"

when it should return "*** *** ***".

Replace this line with your code. 
def censor(text,word):
    text.split(" ")
    for i in text:
        if i==word:
            text=text.replace(i,"*" *len(word))
    return text


so you are going for replace again?

if you use replace correctly, this is a one liner


That is the confusion. I feel that everything is right .


add a function call so you can see what is happening.

next problem:

text.split(" ")

you split the the string into a list, but you don't store the list anywhere? because you don't, the for loop will loop over each letter in text (rather then the words)

but if you do use split(), you can't use replace() since it for strings, not lists.


Can you tell me any other way of doing it so that i don't have to use join. Because i dont clearly understand join

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


well you could you use a for loop and use + to join the string together.

But join is so much better, you simply specify between the quotation marks what you want to join the list together with, and then which list you want to join together between the parentheses and that is it? You can also read documentation on join?


Thank you so much for the help..:slight_smile: :slight_smile: :slight_smile: