Split for censor

FOR THOSE STILL STRUGGLING
I wrote this code and it functioned well, check it out.
def censor(text,word):
wrd= “*” * len(word)
split = text.split()
for i in split:
if i==word :
txt=text.replace(word,wrd)
print “”.join(txt),
return “”.join(txt)
censor(“hey there here am back” , “here”)

.replace() will replace all instances of the word. So then why bother with the loop, split and all the other things you wrote? Replace can do all the heavy lifting for you, the question is how desirable this is in a learning process. Opinions on this matter might vary.

also, replace() has an edge case (which the exercise doesn’t test). for example:

censor("then the bar opened", "the")

will result in ***n *** bar opened. then gets partial censored, which might not be desirable if you wrote a language filter for example. hello would then become ****o