Censor Dispenser Part Three Help

I’m having a hard time cleaning up the output for part three of the Censor Dispenser project (proprietary_terms). This is the code I’m using:

def censor_propietary_terms(email):
    for term in proprietary_terms:
        email = email.replace(term, 'X')
    return email

If I print censor_propietary_terms(email_two) I get the following output:

Good Morning, Board of Investors,

Lots of updates this week. The Xs 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 X has access to the world wide web has increased exponentially, far faster than we had though the Xs were capable of.

Not only that, but we have configured X X to allow for communication between the system and our team of researcXs. That's how we know X considers Xself to be a X! 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 X is starting to form. This is a major step in the process, as having a X and X will allow X 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

I would really appreciate some help with understanding what’s going on here and how I can return the expected output for this part of the project.

What does clean up mean?

What I mean is to return the expected output which should have censored ‘She’ and ‘Her’, should not have censored ‘researcXs’, and should have completely censored ‘Xself’.

some words should be censored if the bad word is in it, but not others? seems inconsistent.

You may want to start paying attention to word boundaries and consider words on their own instead of running replace on the whole thing.

Got it, I’ll attempt to implement your suggestion. Thank you.

Please could you provide a code snippet which will point me in the right direction?

Don’t know what direction that is.

If you want words you’d be looking to split the text wouldn’t you? Specifically you’d want to split at boundaries of alphabetical and non-alphabetical characters, so you could use str.isalpha to detect that. (Yes, that means making a loop, stepping through the input, testing each character and deciding whether or not to make a cut there)

def censor_propietary_terms(email):
    new_email = email
    for term in proprietary_terms:
        new_email = new_email.replace(term, 'X')
    return email