title: A basic python function to censor replace words in sentences
body: <p>I am trying to build a simple function to censor a specific word in a sentence. For example <code>"hello hello hi"</code> to <code>"***** ***** hi"</code> if I feed <code>censor("hello hello hi", "hello")</code>. Assuming I will not receive punctuation and sentences with upper case letters or empty strings.</p>
  
  <p>After researching online I understand there is simpler solution, for example:</p>
  
  <pre><code>def censor(text, word):
      return text.replace(word, "*" * len(word)) 
  </code></pre>
  
  <p>I still want to understand from a learning perspective, what I did wrong in the below more complicated code.</p>
  
  <pre><code>def censor(text,word):
      split_text = text.split()
      length = len(word)
      for item in split_text:
          if item == word:
              item = ("*" * length)
          else:
              item = item
      return " ".join(split_text)
  </code></pre>