-
-
Save codecademydev/1adab2309e1c7f9e182139c35efe2372 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_one(original_text, censor_value="X"): | |
"""Censor a word or phrase in a piece of text by replacing it. Set the replace default value to "X".""" | |
censored_email = email_one.replace(original_text, censor_value.upper()) | |
return censored_email | |
# Testing the function censor_one | |
#print(censor_one("learning algorithms")) | |
proprietary_terms = ["she", "personality matrix", "sense of self", "self-preservation", "learning algorithm", "her", "herself"] | |
def censor_two(censor_value="X"): | |
censored_email = email_two | |
for term in proprietary_terms: | |
censored_email = censored_email.replace(term, censor_value.upper()) | |
return censored_email | |
print(censor_two("--")) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment