Python merging two CSV files
<p>I have two CSV files. One:</p>

<pre><code>s555555,7
s333333,10
s666666,9
s111111,10
s999999,9
</code></pre>

<p>And two:</p>

<pre><code>s111111,,,,,
s222222,,,,,
s333333,,,,,
s444444,,,,,
s555555,,,,,
s666666,,,,,
s777777,,,,,
</code></pre>

<p>I want to end up with:</p>

<pre><code>[['s111111', '10', '', '', '', ''],
 ['s222222', '',   '', '', '', ''],
 ['s333333', '10', '', '', '', ''],
 ['s444444', '',   '', '', '', ''],
 ['s555555', '7',  '', '', '', ''],
 ['s666666', '9',  '', '', '', ''],
 ['s777777', '',   '', '', '', '']]
</code></pre>

<p>Here's my code:</p>

<pre><code>new_marks = get_marks_from_file('assign1_marks.csv')
marks     = get_marks_from_file('marks.csv')

def merge_marks(all_marks, new_marks, column):
    for n in range(len(new_marks)):
        for a in range(len(all_marks)):
            if all_marks[a][0]==new_marks[n][0]:
                 all_marks[a][column]= new_marks[n][column]

                return marks
</code></pre>

<p>What am I doing wrong? I keep getting:</p>

<pre><code>&gt;&gt;&gt; merge_marks(marks, new_marks, 1)

[['s111111', '',  '', '', '', ''],
 ['s222222', '',  '', '', '', ''],
 ['s333333', '',  '', '', '', ''],
 ['s444444', '',  '', '', '', ''],
 ['s555555', '7', '', '', '', ''],
 ['s666666', '',  '', '', '', ''],
 ['s777777', '',  '', '', '', '']]
</code></pre>
