May I know why this solution does not work? Thank you

def censor(text, word):
  my_text_split = text.split(" ")

  for word1 in my_text_split:
    if word1 == word:
      word1 = "*" * len(word)
  return " ".join(my_text_split)

How can I use split( ) to make censor?

Because word1 contains copy of the values in list, change made to word1 won’t persist, given the loop will just assign next value in list to word1 in the following loop iteration.


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