Can someone please help explain why the for loop in this code only seems to run once? The output is simply “***” instead of “*** *** ***”. I know that this is not the conventional way of solving this task but I am exploring other methods to see what I can come up with.


def censor(text, word):
text_split = text.split()
new_text = ""
for i in text_split:
if i == word:
new_text += ‘*’ * len(word) + " "
new_text += ""
return new_text

print censor(“hey hey hey”, “hey”)

<do not remove the three backticks above>


How much indentation is there on the return line? Is it inside the loop?


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.