10. Censor


Hi All!
I've read these topic in other posts, but couldn't find the answear for my code.

I wrote the code, which is below. The error is:
Oops, try again. Your function fails on censor("hey hey hey","hey"). It returns "hey hey hey" when it should return "*** *** ***".

Can you help we with guiding to the solution?

def censor(text, word):
    new_text = text.split()
    censored = ""
    for w in new_text:
        if w == word:
            w = "*" * len(word)
            censored += w
    result = ' '.join(new_text)
    return result



result = ' '.join(new_text)

what is stored in new_text?


splitted text with word (w) changed in loop
maybe looping wasn't saved in new_text?


I managed :slight_smile: I changed "if's" content and order

if w == word:
censored += "*" * len(word) + " "

    (...) and

' '.join(censored)
return censored[:-1]


very good, that was the point i was trying to make :wink:

very good you managed it :slight_smile: Even better that you fix it yourself


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