10. Censor


I want to solve this task thorugh next steps: replace the word on ***.
But my code replace only the last word

Replace this line with your code. 
def censor (text,word):
    text = text.split()
    for i in text:
        if word in text:
            word1 = word_len * '*'
            return ' '.join(text)
print censor('Hello guys guys','guys')


What do you think happens when you remove from a list that you're currently looping through? Would the loop be entirely unaffected? How many times would your loop need to run to do its job? How many iterations do you think it does? How many does it do? (add a print in it to find out)


def censor(text,word):
    return text.replace(word,"*" * len(word))

Share a simple method.


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