-
-
Save codecademydev/b7d3e100bd22245f0626562158c931ac 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() | |
proprietary_terms = ["she", "She", "personality matrix", "sense of self", "self-preservation", "learning algorithm", "personality", "Personailty", "herself", "Herself", "her", "Her", "Helena"] | |
negative_words = ["concerned", "behind", "danger", "dangerous", "alarming", "alarmed", "out of control", "help", "HELP", "unhappy", "bad", "upset", "awful", "broken", "damage", "damaging", "dismal", "distressed", "distressed", "concerning", "horrible", "horribly", "questionable"] | |
def censoreText(textToScan, textToRemove): | |
if textToRemove in textToScan: | |
return textToScan.replace(textToRemove, 'REDACTED') | |
def censoreTextGreatly(textToScan, lstOfTextToRemove): | |
objectLst = [''] | |
objectLst[0] = textToScan | |
for i in lstOfTextToRemove: | |
if i in objectLst[0]: | |
objectLst[0] = objectLst[0].replace(i, 'REDACTED') | |
return objectLst[0] | |
def censoreGreatlyAndLightenTone(textToScan, LstOfNegativeText): | |
objectLst = [''] | |
objectLst[0] = textToScan | |
for i in LstOfNegativeText: | |
if i in objectLst[0]: | |
objectVar = objectLst[0].find(i) | |
for j in LstOfNegativeText: | |
if j in objectLst[0][objectVar + 1:]: | |
objectLst[0] = objectLst[0][:objectVar + 1] + objectLst[0][objectVar + 1:].replace(i, 'REDACTED') | |
return censoreTextGreatly(objectLst[0], proprietary_terms) | |
def censoreAll(textToScan): | |
objectLst = [''] | |
objectLst2 = [''] | |
objectLst3 = [] | |
objectLst[0] = textToScan | |
objectLst[0] = censoreTextGreatly(objectLst[0], proprietary_terms) | |
objectLst[0] = censoreTextGreatly(objectLst[0], negative_words) | |
objectLst2[0] = objectLst[0].replace('\n', ' lineBreak ') | |
objectLst3 = objectLst2[0].split(' ') | |
y = 0 | |
while y < len(objectLst3) - 1: | |
if (objectLst3[y] == 'REDACTED') or (objectLst3[y] == 'REDACTEDe') or (objectLst3[y] == 'REDACTEDous') or (objectLst3[y] == 'REDACTEDly') or (objectLst3[y] == 'REDACTED\'s') or (objectLst3[y] == 'REDACTED.') or (objectLst3[y] == 'REDACTEDs') or (objectLst3[y] == 'REDACTED!') or (objectLst3[y] == 'REDACTEDe.'): | |
if y == 0 and (not objectLst3[1] == 'lineBreak'): | |
objectLst3[y + 1] = 'REDACTED' | |
continue | |
if not y == (objectLst3.index(objectLst3[-1])): | |
if not objectLst3[y + 1] == 'lineBreak': | |
objectLst3[y + 1] = 'REDACTED' | |
if not objectLst3[y - 1] == 'lineBreak': | |
objectLst3[y - 1] = 'REDACTED' | |
y += 2 | |
y += 1 | |
objectLst[0] = ' '.join(objectLst3) | |
objectLst[0] = objectLst[0].replace('lineBreak', '\n') | |
return objectLst[0] | |
print(censoreAll(email_four)) | |
#remember to record any new methods, functions or loops in your notes when you done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks so much! I had a problem with email four and as your method is slighty similiar to mine, it helped me understand it exactly and write a proper solution!