title: how to merge some columns data from different txt files in Python?
body: <p>I have some txt files, which need to extract certain columns out and store in one txt file.<br/></p>
  
  <p>a1.txt: </p>
  
  <blockquote>
    <p>53,  42<br/>  54,  38<br/>  55,  37<br/>  57,  48
    <br/></p>
  </blockquote>
  
  <p>b1.txt:<br/></p>
  
  <blockquote>
    <p>45,  15,  30,  2<br/> 16,  59,  31,  4<br/> 87,  09,  32,  5<br/>
    58,  16,  33,  3<br/></p>
  </blockquote>
  
  <p>what i need is 
  c.txt (add the last column of b1.txt to the a1.txt):<br/></p>
  
  <blockquote>
    <p>53,  42, 2<br/> 54,  38, 4<br/> 55,  37, 5<br/> 57,  48, 3<br/></p>
  </blockquote>
  
  <p>the 4th column of <code>b.txt</code> should be added to the 5th column of <code>a.txt</code>. Then create a new file <code>c.txt</code>.
  I try some code, but it did not work. cmd said <code>"TypeError: list indice must be integers, not srt"</code>. 
  I have no idea how to merge the columns from different files together. Hopefully someone could help me to revise the code. Thank you so much!</p>
  
  <pre><code>def readf(filename):
      lines=file(filename).readlines()
      for i in lines:
          data=i.split()
      return data
  
  fa=readf('a1.txt')
  fb=readf('b1.txt')
  
  lines=[]
  for i in fa:
      s=fa[i]+fb[3]
      s+='\n'
      lines.append(s)
  
  with open ('c.txt','w') as f:
      f.writelines(lines)
      f.close&gt;
  </code></pre>