Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created September 8, 2020 09:31
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/914c7b4e0f95d5889c4fbffe00992c3f to your computer and use it in GitHub Desktop.
Save codecademydev/914c7b4e0f95d5889c4fbffe00992c3f 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()
punctuation = ['.', '?', '!', ',']
proprietary_terms = ["she", "personality matrix", "sense of self", "self-preservation", "learning algorithms", "her", "herself"]
negative_words = ['concerned', 'behind', 'danger', 'dangerous', 'alarming', 'alarmed', 'out of control', 'help', 'unhappy', 'bad', 'upset', 'awful', 'broken', 'damage', 'damaging', 'dismal', 'distressed', 'distress', 'concerning', 'horrible', 'horribly', 'questionable']
def censor_email_four(email_four):
email_4 = email_four.split()
words_with_punctuation = []
words_to_censor = proprietary_terms + negative_words
for j in range(len(words_to_censor)):
for k in range(len(punctuation)):
if words_to_censor[j]+punctuation[k] in email_4:
words_with_punctuation.append(words_to_censor[j]+punctuation[k])
words_to_censor_final = words_to_censor + words_with_punctuation
for i in range(len(email_4)):
if email_4[i].lower() in words_to_censor_final:
email_4[i-1] = len(email_4[i-1]) * "x"
email_4[i] = len(email_4[i]) * "x"
email_4[i+1] = len(email_4[i+1]) * "x"
email_4_final = ' '.join(email_4)
return email_4_final
print(censor_email_four(email_four))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment