How to extract columns from multiple rows in Python using nested loops?
<p>I have a list with 3 sequences</p>

<pre><code>seq_list = ['ACGT', 'ATTT', 'ACCC']
</code></pre>

<p>I want to extract the columns from the the list and store it in another list using nested loops in python</p>

<p>The final output should be </p>

<pre><code>seq_list = ['AAA', 'CTC', 'GTC','TTC']
</code></pre>

<p>I have written the following code, but it does not yield the desired output.</p>

<pre><code>column = []
for i in range(len(seq_list[0])):   #Length of the row
    for j in range(len(seq_list)):    #Length of the column
        column.append(seq_list[j][i])
         print column
</code></pre>

<p>By your method I made little modification, for each inner <code>for</code> loop i created a <code>string</code> and then after inner <code>for</code> loop ends i appended it to <code>column</code>:</p>

<pre><code>seq_list = ['ACGT', 'ATTT', 'ACCC']
column = []
for i in range(len(seq_list[0])):   #Length of the row
    string = ""
    for j in range(len(seq_list)):    #Length of the column
        string += seq_list[j][i]
    column.append(string)
print column
</code></pre>

<p><strong>Output:</strong></p>

<pre><code>['AAA', 'CTC', 'GTC', 'TTC']
</code></pre>

<p>Although you could use @alecxe code(using <code>zip</code> and <code>join</code>). I think it's cool and more pythonic.</p>

python python-2.7 for-loop extract multiple-columns