Censor Dispenser project

Hello,

I am trying to do part 3 on the censor dispenser project which says the following:

Write a function that can censor not just a specific word or phrase from a body of text, but a whole list of words and phrases, and then return the text.

Mr. Cloudy has asked that you censor all words and phrases from the following list in email_two.

proprietary_terms = ["she", "personality matrix", "sense of self", "self-preservation", "learning algorithm", "her", "herself"]

I have tried doing this but when i run my code, only one or two of the words have been replaced:

Good Morning, Board of Investors,

Lots of updates this week. The learning algorithms have been working better than we could have ever expected. Our initial internal data dumps have been completed and we have proceeded with the plan to connect the system to the internet and wow! The results are mind blowing.

She is learning faster than ever. Her learning rate now that she has access to the world wide web has increased exponentially, far faster than we had though the learning algorithms were capable of.

Not only that, but we have configured her personality matrix to allow for communication between the system and our team of researchers. That’s how we know she considers # to be a she! We asked!

How cool is that? We didn’t expect a personality to develop this early on in the process but it seems like a rudimentary sense of self is starting to form. This is a major step in the process, as having a sense of self and self-preservation will allow her to see the problems the world is facing and make hard but necessary decisions for the betterment of the planet.

We are a-buzz down in the lab with excitement over these developments and we hope that the investors share our enthusiasm.

Till next month,
Francine, Head Scientist

This is my code, can someone please tell me where i am going wrong:

def censor(email):
  global proprietary_term    
  for i in proprietary_terms:
    censored_email = email.replace(i,'#')
  return censored_email

print (censor(email_two))

Thank you

What happens you actually call email.replace()? What does it return and what are you then doing with the returned object?

1 Like

for the words that are required to be removed, it only removes one

Your code is reading through these items one by one and attempting to alter the string. Why might only one of the changes appear? Perhaps take a note of exactly which change is recorded and work backwards to determine why that partiuclar change is the only one observed in your return.