Skip to content

Instantly share code, notes, and snippets.

@ejmurray
Created July 18, 2015 10:26
Show Gist options
  • Save ejmurray/b36086182500837c200f to your computer and use it in GitHub Desktop.
Save ejmurray/b36086182500837c200f to your computer and use it in GitHub Desktop.
The answer to the codeacademy censor question. Only tested in PyCharm.
def censor(text, word):
word_length = len(word)
print(text)
print(word_length)
censored_word = word_length * '*'
print(censored_word)
separated_text = text.split()
print(separated_text)
update = [censored_word if x == word else x for x in separated_text]
print(update)
censored_text = " ".join(update)
print(censored_text)
return censored_text
censor('here is the text here', 'here')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment