title: Why code not working while replacing the text in file
body: <p>I have a file called <code>test.txt</code>.</p>
  <p>I need to convert one string in the file which matches the dictionary.</p>
  <p><code>test.txt</code>:</p>
  <pre><code>abc
  asd
  ds
  {{  PRODUCT CATEGORY  }}
  fdsavfacxvasdvvc
  dfvssfzxvdfvzd 
  </code></pre>
  <p>Code is below:</p>
  <pre><code>data = {'PRODUCT CATEGORY':'Customer'}
  all_files = ['test.txt']
  out_files = ['ut.txt']
  read_dict = {}
  for file in all_files:
      with open(file,'r') as read_file:
          lines = read_file.readlines()
          read_dict[file] = lines
  for in_f, out_f in zip(all_files, out_files):
      with open(in_f,'r') as read_file:
          lines = read_file.readlines()
      with open(out_f,'w+') as write_file:        
          for line in lines:
              updated_line = []
              for word in line.split():
                  if word in data:
                      updated_line.append(data[word])
                  else:
                      updated_line.append(word)
              write_file.writelines(&quot; &quot;.join(updated_line))                            
              print (&quot; &quot;.join(updated_line))  
  </code></pre>
  <p>There is a space at the end and at the beginning <code> PRODUCT CATEGORY </code></p>
  <p>Expected output:</p>
  <pre><code>abc
  asd
  ds
  Customer
  fdsavfacxvasdvvc
  dfvssfzxvdfvzd 
  </code></pre>