Practice Makes Perfect



def censor(text,word):
  text.split(" ")
  for idx , item in enumerate(text):
    if item == word:
      text[idx] = '*' * len(item)
  " ".join(text)
  return text


Your function fails on censor(“hey hey hey”,“hey”). It returns “hey hey hey” when it should return " *".


here, you split text:

text.split(" ")

you split the string into a list, but don’t store this list anywhere? So text is still a string, so it will loop letter by letter, so item will never equal word

same problem with .join(), you join the list into a string, but don’t store the returned string anywhere?


can i store in the same name list text like this

text = text.split(" ")


yes, now you update the variable containing a string with a list, that is a very good idea :slight_smile:


It works thanks :grin::grin::grin::grin::grin::grin::grin::grin::grin::grin::grin::grin::grin::grin::grin::grin::grin::grin::grin::grin: