Sums of entries, Python
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/14712268/summing-up-values-of-columns-from-multiple-files">summing up values of columns from multiple files</a>  </p>
</blockquote>



<p>I have a small problem here, I'm trying to sum up entries from multiple files (50), and each of them contain 3 columns. for example, using the first 3 files: file1.txt, file2.txt, file3.txt which look like:</p>

<p>file1.txt:</p>

<pre><code>2 3 4
1 5 6
5 4 7
</code></pre>

<p>file2.txt:</p>

<pre><code>1 2 1
2 3 2
4 3 1
</code></pre>

<p>file3.txt:</p>

<pre><code>6 1 1
1 3 0
3 4 5
</code></pre>

<p>So my question is how do i sum up all the entries from column one, column two and column three from the 50 files to end up with a file that looks like:</p>

<p>output.txt:</p>

<pre><code>9 6 6
4 11 8
12 11 13
</code></pre>

<p>I've read in the 50 files and appended them but I'm having trouble actually summing the entries one by one.</p>

<p>so I've done this:</p>

<pre><code>for p in range(50):
    locals()['first_col%d' % p] = []
    locals()['second_col%d' % p] = []
    locals()['third_col%d' % i] = []

for i in range(1,50):
    f = open("file"+str(i)+".txt","r")
    for line in f:
        locals()['fist_col%d' % i].append(float(line.split()[0]))
        locals()['second_col%d' % i].append(float(line.split()[1]))
        locals()['third_col%d' % i].append(float(line.split()[2]))

f.close()
</code></pre>

<p>I'm trying to think of a way to put this in a loop that will read in all the <code>first_cols</code> (<code>first_col1</code> ,<code>first_col2</code>, <code>first_col3</code>, etc), <code>second_cols</code> and <code>third_cols</code> and sum up the entries.</p>
