10. Censor


#1

https://www.codecademy.com/courses/learn-python/lessons/practice-makes-perfect/exercises/censor-

Hey guys :slight_smile:

Last time I posted my code a moderator showed me that my code was correct, but for some reason it was returning the wrong answer on my session. Iโ€™m not sure if Iโ€™m having the same issue/glitch, or if my code is okay?

Thanks for your help :slight_smile:



def censor(text, word):
  text.split()
  new = []
  for spiel in text:
    if spiel != word:
      new.append(spiel)
    else:
      bad_word = "*" * len(spiel)
      "".join(bad_word)
      new.append(bad_word)
  return "".join(new)



#2

here:

text.split()

you split the string into a list, but you donโ€™t store the list anywhere?

this line:

"".join(bad_word)

is not doing anything, you can remove it

finally, here:

return "".join(new)

you need a space to join the words together, currently the words are stitched together without spaces between them


#3

Thank you so much for your advice! I fixed as per your notes above and the code worked great :slight_smile:


#4