Censor


#1


CENSOR

CENSOR

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

It should return "*** *** ***".

Replace this line with your code. 
def censor(text,word):
    text=text.lower()
    t=text.split()
    s=""
    for i in t:
        if i==word:
            o=len(word) * "*"
            s=s+o
        else:
            s=s+i
        result="".join(s)
    return result


#2

For this exercise we do not need to modify the inputs. What if the word has a capital letter in it?

This will return a line of text with no white space. There should be spaces in the text just as there were in the input. Instead of using a string to accumulate the censored text, try using a list, then join with a space separator.


#3

better use string replace method here


#4

Not really advisable. That method has not come up yet (in the first set of units). Better to use what we know for this one.


#5

what should i do now?
how can i solve this?


#6

You have the steps in place, just change your working variable to a list and append either len(word) * "*" or 'term'.

censored = []
for term in text:
    if term == word:


 return " ".join(censored)

#7

It's done with your advice

Thanks a lot!!!:grinning:


#8

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