-
-
Save codecademydev/4505cc0910a8dbcefaa7257ed4da8697 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
# 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() | |
def censor(word,text): | |
new_word = '' | |
for item in word: | |
new_word += '*' | |
return text.replace(word.lower(),new_word).replace(word.upper(),new_word).replace(word.title(),new_word) | |
#print(censor("learning algorithms",email_one)) | |
def censor_list(lst,text): | |
new_text = text | |
for word in lst: | |
new_word = '' | |
for item in word: | |
new_word += '*' | |
new_text = new_text.replace(word.lower(),new_word).replace(word.upper(),new_word).replace(word.title(),new_word) | |
return new_text | |
proprietary_terms = ["she", "personality matrix", "sense of self", "self-preservation", "learning algorithm", "her", "herself"] | |
#print(censor_list(proprietary_terms,email_two)) | |
def censor_if_twice(lst,text): | |
new_text = censor_list(proprietary_terms,text) | |
count = 0 | |
for word in lst: | |
if word in text: | |
count += 1 | |
if count > 1: | |
new_word = '' | |
for item in word: | |
new_word += '*' | |
new_text = new_text.replace(word.lower(),new_word).replace(word.upper(),new_word).replace(word.title(),new_word) | |
else: | |
continue | |
return new_text | |
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"] | |
#print(censor_if_twice(negative_words,email_three)) | |
def censor_all(text): | |
new_text = '' | |
for letter in text: | |
if letter == '\n' or letter == '\r' or letter == ' ': | |
new_text += letter | |
else: | |
new_text += '*' | |
return new_text | |
#print(censor_all(email_four)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment