Censor Dispenser

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

def censor_two(email):

for terms in proprietary_terms:

censored_email = email.replace(terms, ‘x’*len(terms))

return censored_email

Hi everyone,
when a run this piece of code only the last element of the list ‘herself’ is affected. Can anyone help explain why, i thought the for loop would iterate through each item of the list. Thanks in advance.

indentation has not shown sorry, the return is in line with the for loop.

You can format code on the forums if you follow the guidance on this post- Code_Formatting_FAQ.

It’d be worth taking a close look at what happens when you use the .replace string method and why assignment is used- https://docs.python.org/3/library/stdtypes.html#str.replace

Thank you for the reply! I appreciate the help!