Please find the problem in my code



def censor(text, word):
word_list = text.split()
star = “*” * len(word)
result = ""
for item in word_list:
if item == word:
item = star
result = " ".join(word_list)
return result

print censor(“this hack is wack hack”, “hack”)

This code just prints the same text as output.


This will have no effect on the original text. You are simply replacing the iterator, which is immediately following that replaced again by the next term in the iteration.


A post was split to a new topic: Function


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