Skip to content

Instantly share code, notes, and snippets.

@prithajnath
Created March 27, 2017 17:02
Show Gist options
  • Select an option

  • Save prithajnath/d0647cb1a4a9b1dece66752ea491c856 to your computer and use it in GitHub Desktop.

Select an option

Save prithajnath/d0647cb1a4a9b1dece66752ea491c856 to your computer and use it in GitHub Desktop.
def replaceWord(sentence,word):
words = sentence.split()
for i in range(len(words)):
if word == words[i]:
words[i] = "".join(['-' for _ in range(len(word))])
break
return " ".join(words)
def replaceMultiWords(sentence,words):
new_str = sentence
for i in words.split():
new_str = replaceWord(new_str,i)
return new_str
x = "I fucking love to eat some motherfucking dope ass pizza"
print replaceMultiWords(x,'fucking dope ass motherfucking')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment