Censor


#1


Censor

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=text.lower()
    text.split(" ")
    word=word.lower()
    count=0
    
    for i in text:
        if i==word:
            text=text.replace(i,"*" *len(word))
    
    return text


#2

so you are going for replace again?

if you use replace correctly, this is a one liner


#3

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


#4

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.


#5

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.lower()
    text=text.split(" ")
   # word=word.lower()
    final=[]
    count=0
    
    for i in text:
        if i==word:
            final.append("*" *len(word))
        else:
            final.append(i)
    final=" ".join(final)
    
    return final

#6

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?


#7

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


#8