I am working through the Censor Dispenser project, currently on the task for email_two. I feel I am in the ballpark but I can’t quite get there. My code is as follows:
proprietary_terms = ["she", "personality matrix", "sense of self", "self-preservation", "learning algorithm", "her", "herself"] def censor_text2(text): for phrase in proprietary_terms: proprietary_terms.append(phrase.title()) if phrase in text: new_text = text.replace(phrase, "******") return new_text print(censor_text2(email_two))
proprietary_terms.append(phrase.title()) to make sure it’s including capitalized proprietary words as well. When I run this, it is only replaces the first ‘she’ in the list (and appends a ‘She’ to the proprietary_terms). I know the
return is causing the function to end, but shouldn’t it be performing this for each phrase in proprietary_terms? If I leave
return out, I get an infinite loop.
My next instinct was to iterate over
range(len(proprietary_terms), however it doesn’t like that because the list is comprised of strings, and not integers.
Can anyone give me a nudge in the right direction?