Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created February 27, 2021 06:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/1317840ed650d68d84b468df9201db5c to your computer and use it in GitHub Desktop.
Save codecademydev/1317840ed650d68d84b468df9201db5c to your computer and use it in GitHub Desktop.
Codecademy export
# These are the emails you will be censoring. 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()
proprietary_terms = ["she", "personality matrix", "sense of self", "self-preservation", "learning algorithm", "her", "herself"]
def caps_and_title_terms(list):
for i in range(len(list)):
list.append(list[i].title())
list.append(list[i].lower())
list.append(list[i].upper())
caps_and_title_terms(proprietary_terms)
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"]
caps_and_title_terms(negative_words)
def censor(banned_text, email):
if banned_text in email:
censored_email = email.replace(banned_text, "***")
return(censored_email)
##print(email_one)
##print("learning algorithms", email_one)
def censor_list(email):
for i in range(len(proprietary_terms)):
if proprietary_terms[i] in email:
email = email.replace(proprietary_terms[i], "***")
return(email)
##print(email_two)
##print(censor_list(email_two))
def censor_negative_words(email):
email = censor_list(email)
negative_tally = 0
for i in range(len(negative_words)):
if negative_words[i] in email:
negative_tally += 1
for i in range(len(negative_words)):
if negative_tally > 2:
email = email.replace(negative_words[i], "***")
return(email)
##print(email_three)
##print(censor_negative_words(email_three))
def censor_everything(email):
split_email = email.split()
censored_words = proprietary_terms + negative_words
for i in range(len(split_email)):
if split_email[i] in censored_words:
split_email[i-1] = len(split_email[i-1]) * "***"
split_email[i] = len(split_email[i-1]) * "***"
split_email[i+1] = len(split_email[i-1]) * "***"
final_email = ' '.join(split_email)
return final_email
print(email_four)
print(censor_everything(email_four))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment