Censor


#1



Hello! I need some help with this exercise.


Error looks like: "Oops, try again. Does your censor function take exactly two arguments, a text string and a word to replace with asterisks? Your code threw a "sequence item 0: expected string, list found" error."


def censor(text, word):
    y = []
    x = text.split()
    for i in text:
        if i == word:
            y.append('*')
        else:
            y.append(x)
    return ''.join(y)


Any suggestions?


#2

lets start here:

for i in text:

what is in the variable text? Looping over a string will go over the string letter by letter, i would loop over the words instead, which variable holds the words?

then this line:

y.append('*')

are you sure you just want to append one * for the whole word? i would want to add the number of letters word is long? How to achieve this?

next problem:

y.append(x)

what does x contain? a list with all the words, are you sure you want to append this to y every time the word doesn't need to be censored? I would just append the word which doesn't have to be censored.

and finally:

return ''.join(y)

the characters between the apostrophes ('') determines what join uses to join the words, in your case, nothing. Which means there will be no spaces between the words


#3

Thanks a lot! I fixed all my problems and the program finally worked.


#4