I am trying to write a function that will convert a dedicated word within a string into asterisks. Basically, I want to censor a word from a string (ex. change "Hello World" into "Hello *****" if I made "World" the dedicated word). I tried to write the following code, but the code will not convert words into asterisks.
def censor(text, word):
a = text.split()
replace = ""
for i in word:
replace += "*"
for i in a:
if i == word:
i = replace
result =' '.join(a)
return result
Can someone help me? Everything in the code seems to work except for the line i = replace.
Thanks!