Practice Makes perfect: censor


is the .replace() function not working for a list?

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


because its not a function, its a method for strings


I see thanks. Ill go look for a method for a list.


you can use range() to get a list of numbers which can match indexes of your list (make sure to split the string before the loop)


I'm not quite understanding how range() will help solve this problem.


well, if you make a list out of text:

words = text.split()

we can loop over words using range:

for i in range(len(words)):

check if i equals word (which means it requires censoring), then you can use i (which matches index of your words list) to update items in your list


Ahhh I understand now, thanks.