Skip to content

Instantly share code, notes, and snippets.

@ProProgrammer
Last active December 23, 2015 22:09
Show Gist options
  • Save ProProgrammer/6700823 to your computer and use it in GitHub Desktop.
Save ProProgrammer/6700823 to your computer and use it in GitHub Desktop.
This function called censor that takes two strings, text and word, as input and returns the text with the word you chose replaced with asterisks.
def match_characters(word1, word):
for i in word1.lower():
for j in word.lower():
if i == j:
return True
else:
return False
def censor(text, word):
textlist = text.split()
for char in textlist:
if match_characters(char, word):
text = text.replace(char, '*' * len(char))
return text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment