title: Replace Words in a line from a file in python
body: <p>I am trying to replace certain words in file which has mutliplelines. Below is the code I wrote. Please note I am still learning python.</p>
  
  <pre><code>ParsedUnFormattedFile = io.open("test.txt", "r", encoding="utf-8", closefd=True).read()
  
  remArticles = {' a ':'', ' the ':'', ' and ':'', ' an ':''}
  
  for line in ParsedUnFormattedFile:
      for i in remArticles.keys():
             words = line.split()
             ParsedReplacementFile = ParsedUnFormattedFile.replace(words,remArticles[i])
  
      FormattedFileForIndexing =  io.open("FormattedFileForIndexing.txt", "w", encoding="utf-8", closefd=True)
      FormattedFileForIndexing.write(ParsedReplacementFile)
  </code></pre>
  
  <p>If I am replacing by directly reading a line, it replaces only 1 word out of all words. It's usually 'the' in my system.</p>
  
  <p>So I wanted to split and look for ever word and then replace it. However I get below error:</p>
  
  <pre><code>line 14, in &lt;module&gt;
      ParsedReplacementFile = ParsedUnFormattedFile.replace(words,remArticles[i])
  TypeError: coercing to Unicode: need string or buffer, list found
  </code></pre>
  
  <p>How can I get this rectified?</p>
  
  <p>Thanks</p>