Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created April 2, 2020 14:36
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/a1d700b0385ac37e28770fb4b320d073 to your computer and use it in GitHub Desktop.
Save codecademydev/a1d700b0385ac37e28770fb4b320d073 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()
#censor_1
def censor_one(text_one):
if "learning algorithms" or "Learning algorithms" in text_one:
return text_one
#censor_2
proprietary_terms = ["she", "personality matrix", "sense of self", "self-preservation", "learning algorithm", "her"]
proprietary_terms_capital=[]
for x in proprietary_terms:
proprietary_terms_capital.append(x[0].upper() + x[1:])
proprietary_terms_complete = proprietary_terms + proprietary_terms_capital
def censor_two(list_1,text_two):
for x in list_1:
if x in text_two:
return text_two
#print(censor_two(proprietary_terms_complete, email_two))
negative_words = ["concerned", "out of control", "behind", "dangerous", "danger", "alarming", "alarmed", "help", "unhappy", "bad", "upset", "awful", "broken", "damage", "damaging", "dismal", "distressed", "distressed", "concerning", "horrible", "horribly", "questionable"]
negative_words_capital=[]
for x in negative_words:
negative_words_capital.append(x[0].upper() + x[1:])
negative_words_complete = negative_words + negative_words_capital
complete_censor_list = negative_words_complete + proprietary_terms_complete
negative_words_1 = []
words_before = []
words_after = []
#censor_3
def censor_three(list_1, list_2, text_three):
for v in negative_words_complete:
negative_words_1.append('fuck'+v)
for p in list_1:
for l in list_2:
if p in text_three:
text_three=text_three.replace(l, 'fuck'+l)
text_three=text_three.replace("fuck", '', 2)
for q in negative_words_1:
if q in text_three:
text_three = text_three.replace(q, (len(q)-4)*'#')
text_three=text_three.replace('fuck'+len(q)*'#', len(q)*'#')
return text_three
#print(censor_three(complete_censor_list, negative_words_complete, email_three))
#censor_four
key_words = []
check_list = []
def censor_four(list_4, text_four, text_five):
for x in list_4:
text_four=text_four.replace(x, 'XXXX')
text_four_split = text_four.replace(x, 'XXXX').split()
for y in range(len(text_four_split)):
if 'XXXX' in text_four_split[y]:
key_words.append(text_four_split[y+1])
for z in range(len(text_four_split)):
if 'XXXX' in text_four_split[z]:
key_words.append(text_four_split[z-1])
for XXXX in key_words:
if 'XXXX' in XXXX:
key_words.remove(XXXX)
for v in key_words:
if v not in check_list:
check_list.append(v)
full_check_list = complete_censor_list + check_list
for word in complete_censor_list:
if word in text_five:
return text_five
print(censor_four(complete_censor_list, email_four, email_four))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment