-
-
Save codecademydev/735dfcf26a48d91048f32d48599c2e03 to your computer and use it in GitHub Desktop.
Codecademy export
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#The open() function is opening the text file that the emails are contained in and the .read() method is allowing us to save their contexts to the following variables: | |
email_one = open("email_one.txt", "r").read() | |
email_two = open("email_two.txt", "r").read() | |
email_three = open("email_three.txt", "r").read() | |
email_four = open("email_four.txt", "r").read() | |
def censor_word(email, word): | |
email = email.casefold() | |
word = word.casefold() | |
if word in email: | |
email.replace(word, '***') | |
return | |
def censor_proprietary_terms(email): | |
email = email.casefold() | |
for term in proprietary_terms: | |
term = term.casefold() | |
if term in email: | |
email.replace(term, '***') | |
return | |
def censor_negative_words(email): | |
email = censor_proprietary_terms(email) | |
email_words = ' '.split(email) | |
for negative_word in negative_words: | |
count = 0 | |
for word in email_words: | |
if negative_word in word: | |
count += 1 | |
if (count > 2): | |
email.replace(negative_word,'***') | |
return email | |
def censor_it_all(email): | |
email = censor_negative_words(email) | |
email_censor_split = '***'.split(email) | |
email_updated = '' | |
count = 0 | |
for section in email_censor_split: | |
count += 1 | |
section_words = ' '.split(section) | |
section_words[-1] = '***' | |
if count > 1: | |
section_words[0] = '***' | |
section_words = ' '.join(section_words) | |
section_words += ' *** ' | |
email_updated += section_words | |
return email_updated | |
word = 'learning algorithms' | |
proprietary_terms = ["she", "personality matrix", "sense of self", "self-preservation", "learning algorithm", "her", "herself"] | |
negative_words = ["concerned", "behind", "danger", "dangerous", "alarming", "alarmed", "out of control", "help", "unhappy", "bad", "upset", "awful", "broken", "damage", "damaging", "dismal", "distressed", "distressed", "concerning", "horrible", "horribly", "questionable"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment