10. Censor



Hey, my function returns the text just as he was. I can't figure out where the problem lies.

I thought, that through if word==x: x= ""len(word) the string would be replaced, but somehow it doesn't. I'd be grateful for help!

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

print censor("fu fu fo", "fo")



for x in text:

using a for loop will give you read only values from the list, any changes made to x won't persist

If you want to do this, use range() in the for loop, this gives you indexes which you can use to manipulate text list


Ok solved the problem, thank you very much!!


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