Need censor help


def censor(text,word):
for i in text:
if i==word:
new+=""len(word) + " "
new+=i + " "

return new

Problem is that with this code, getting an extra space for input "Hey Hey Hey" as "*** *** *** " instead of "*** *** ***".How to remove it without using .join() and if using .join() how will the code look like?


The input is a sentence, which split() turns into a list object. Rather than try to construct a sentence manually (where you insert a space), build a temporary list to receive the alternating values.

result = []

result.append(len(word) * "*")


And at the end,

return " ".join(result)