Censor ?. What is wrong with this code?


def censor(text, word):
words = text.split(" ")
for i in words:
if i == word:
seq = "*" * len(word)
words = seq.join(words)
return words
print censor("this hack is wack hack", "hack")

output: ['this', 'hack', 'is', 'wack', 'hack']

Error: Oops, try again.
Your function fails on censor("hey hey hey","hey"). It returns "hey***hey***hey" when it should return "*** *** ***".

Please help me. What is wrong?? And thank you


your code must replace seleted word( word variable ) with '*' in len of word

such as: "hack" must replace by "****"

seq = "*" * len(word)

in here you create the stars but
in here of code:

words = seq.join(words)

you join the list items by that stars, you should replace seq by that word( variable i )
before these, you must change for to,

for i in range(len(words)):
    if words[i] = word:
        seq = "*" * len(word)
        words[i] = seq

now after for loop should add join command, then return new string:

text = ' '.join(words)
return text