Practice Makes perfect: censor


#1



https://www.codecademy.com/courses/python-intermediate-en-rCQKw/1/4?curriculum_id=4f89dab3d788890003000096#


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)


#2

because its not a function, its a method for strings


#3

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


#4

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)


#5

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


#6

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


#7

Ahhh I understand now, thanks.


#8