the code prints " hey *** *** " instead of " *** *** *** " which i find very unusual
im not sure what i can do to change this

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

def censor(text, word):
    x = text.split()
    y = "*" * len(word)
    for i in x:
        if i == word:
    return " ".join(x)


When this problem surfaces I automatically look for a misunderstood built-in method, which to no surprise we find again... list.remove().

First, set this aside (save it to a notepad file) and try solving it without using a built in method or function. It will open your mind to what is actually happening. Then, when this is accomplished and you've tired yourself of all the ways you have discovered, read up on list.remove() and see if you cannot solve this problem on your own.

I'm not being facetious or condescending, only throwing out the gauntlet to help you expand your mind around this problem, and come at it from different directions.


im not sure this is what you wanted me to do by

but i thought that instead of removing the word, i could make a new list and put existing text and the asterisks into it. this would mean that the word has not been removed but placed elsewhere.

again, not sure if this is what you intended me to do but i guess opening my mind help me figure it out.

thanks :smiley:


Please do not read anything more into my expression than the possible outcome of added exploration and experimentation. Ply one's brain for ideas and exhaust all possibilities is more what it meant. Nothing directive or personal.

As to the approach you are attempting, it may be removing a word from the list, but it is not replacing it, only appending the redaction phrase to the end of the list. Therein lies the prevailing concern.


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