Censor Dispenser

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(email=email_one):

if “learning algorithms” in email:

censor="X"

censor*=len("learning algorithms")

email=email.replace("learning algorithms",censor)

return email

#print(censor())

proprietary_terms = [“she”, “personality matrix”, “sense of self”, “self-preservation”, “learning algorithm”, “her”, “herself”]

def censor_two(email=email_two):

for i in proprietary_terms:

if i.title() in email:

  censor="X"

  censor*=len(i)

  email=email.replace(i.title(),censor)

elif i in email:

  email=email.replace(i,censor)

return email

#print(censor_two())

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”]

def censor_three(email=email_three):

for i in negative_words:

if i in email:

  censor="X"

  censor*=len(i)

  email=email.replace(i,censor)

elif i.title() in email:

  censor="X"

  censor*=len(i)

  email=email.replace(i.title(),censor)

return email

#print(censor_three())

#print(email_four)

def censor_four(email=email_four):

email_split=email.split(" ")

for i in range(len(negative_words)):

for j in range(len(email_split)):

  if negative_words[i] in email_split[j]:

    email_split[j]="X"*len(email_split[j])

    email_split[j-1]="X"*len(email_split[j-1])

    email_split[j+1]="X"*len(email_split[j+1])

for i in range(len(proprietary_terms)):

for j in range(len(email_split)):

  if proprietary_terms[i] in email_split[j]:

    email_split[j]="X"*len(email_split[j])

    email_split[j-1]="X"*len(email_split[j-1])

    email_split[j+1]="X"*len(email_split[j+1])

#print(email_split)

censor_email=""

censor_email+=" ".join(email_split)

print(censor_email)

censor_four()

Is there a query about this code that you have? Please see the following links for details on how to ask a good question and therefore get the most useful answers-


and how to format code for the forums-

1 Like