title: Modify a table in .txt file using python
body: <p>I have a .txt file containing a set of data organized as follow:</p>
  <pre><code>(id1) (name1) (x coordinate1) (y coordinate1) (value1)
  (id2) (name2) (x coordinate2) (y coordinate2) (value2) 
  (id3) (name3) (x coordinate3) (y coordinate3) (value3) 
  
  ..... 
  </code></pre>
  <p>Now I want to move all (names) from column 2 to column 4. The code I wrote is this:</p>
  <pre><code>with open(&quot;C:\\path\\to\\input\\file.txt&quot;,&quot;r&quot;) as f:
      rows = list(f)
      table = [[&quot;.&quot;],[&quot;.&quot;],[&quot;.&quot;],[&quot;.&quot;],[&quot;.&quot;],[&quot;.&quot;]]*len(rows)
      for i in range(len(rows)):
          row = rows[i].split(&quot; &quot;)
          table[6*i] = row[0]+&quot; &quot;
          table[6*i+1] = row[2]+&quot; &quot;
          table[6*i+2] = row[3]+&quot; &quot;
          table[6*i+3] = row[1]+&quot; &quot;
          table[6*i+4] = row[4]
          table[6*i+5] = &quot;\n&quot;
      with open(&quot;C:\\path\\to\\output\\file.txt&quot;,&quot;w&quot;) as o:
          o.writelines(table)
  </code></pre>
  <p>it performs the task but the output contains a blank line after each row. I have tried hours to get rid of them but I cannot figure out how to get a correct output. The wrong output is this:</p>
  <pre><code>(id1) (x coordinate1) (y coordinate1) (name1) (value1)
  
  (id2) (x coordinate2) (y coordinate2) (name2) (value2) 
  
  (id3) (x coordinate3) (y coordinate3) (name3) (value3) 
  
  ..... 
  </code></pre>