title: String Replace in python by index wise or by one direction from start to end
body: <p>I'm a newbie who just Started learning Python from YouTube. I am trying to make a program to replace old string Numbers with new string Numbers and facing problems while replacing numbers. Want to replace index-wise (What is its technical term (I don't know)). It can go in one direction or index-wise.</p>
  <p>my string is = <code>(001001001001001001001001001001001001001101100100110110011011001101011010011010110011011)</code></p>
  <p>and I want to replace 101 with 01, 1101 with 11, 1001 with 011, and 11001 with 111,</p>
  <p>so my replaced string/output string will be like this..
  <code>(00011000110001100011000110001100110110011011010110101100110111011) </code>
  As per python's normal string replace method it Cant work Anyone can help my</p>
  <pre><code>string = &quot;001001001001001001001001001001001001001101100100110110011011001101011010011010110011011&quot;
  
  string = string.replace('101', '01').replace('1101', '11').replace('1001', '011').replace('11001', '111')
  
  
  fin.close()
  fin = open(&quot;2x.txt&quot;, &quot;wt&quot;)
  fin.write(string)
  fin.close()
  
  (00011000110001100011000110001100110110011011010110101100110111011)
  </code></pre>