title: Replace row data in file
body: <p>I have two files: <code>file1</code>, <code>file2</code>.</p>
  
  <p>In <code>file1</code> I have lines with data that I'm parsing into <code>list1</code> with skipping empty rows and making an elements lowercase:</p>
  
  <p><strong>file1:</strong></p>
  
  <pre class="lang-none prettyprint-override"><code>dATa02
  datA03
  
  dAta04
  </code></pre>
  
  <pre><code>with open('file1', 'r') as f:
      list1 = [l.lower() for l in (line.strip() for line in f) if l]
  </code></pre>
  
  <p>As a result, I get a data list <code>list1</code>: <code>[ 'data02', 'data03', 'data04' ]</code></p>
  
  <p>In <code>file2</code> I have a row: <code>if [data] in [ "data01", "data02", "data03" ] {</code> which constantly start with <code>if [data] in</code></p>
  
  <p><strong>file2:</strong></p>
  
  <pre class="lang-none prettyprint-override"><code>#somedata
  if [data] in [ "data01", "data02", "data03" ] {
  #somedate
  </code></pre>
  
  <p>I'm using regular expression for parsing data list:</p>
  
  <pre><code>import re
  with open('/file2', 'r+') as f:
      for l in f:
          l_s = row.strip()
          if 'if [data] in ' in row_s:
              data1 = re.findall('"(.\w+)\"*', l_s)
              print(data1)
  </code></pre>
  
  <p>As a result I get another data list <code>list2</code>: <code>[ 'data01', 'data02', 'data03' ]</code></p>
  
  <p>After getting two lists, I perform a comparison:</p>
  
  <pre><code>added = set(list1) - set(list2) #data04
  deleted = set(list2) - set(list1) #data01
  </code></pre>
  
  <p>The question is: How to replace <code>list2</code> from <code>file2</code> to <code>list1</code> from <code>file1</code>?</p>