How to zip a list of lists in python?
<p>I have a list of lists</p>

<pre><code>sample = [['A','T','N','N'],['T', 'C', 'C', 'C']],[['A','T','T','N'],['T', 'T', 'C', 'C']].
</code></pre>

<p>I am trying to zip the file such that only A/T/G/C are in lists and the output needs to be a list</p>

<pre><code>[['AT','TCCC'],['ATT','TTCC']]
</code></pre>

<p>When I use this code:</p>

<pre><code>tt = ["".join(y for y in x if y in {'A','G','T','C'}) for x in sample]
</code></pre>

<p>However, I only get the output as:</p>

<pre><code>['ATT','TTCC']
</code></pre>

<p>Any suggestions where I am going wrong?</p>

<p>In my actual code I am first transposing the lists:</p>

<pre><code>seq_list = [['TCCGGGGGTATC', 'TCCGTGGGTATC', ...]]  # one nested list

numofpops = len(seq_list)

### Tranposing. Moving along the columns only

#column_list = []
for k in range(len(seq_list)):
    column_list = [[] for i in range(len(seq_list[k][0]))]
    for seq in seq_list[k]:
        for i, nuc in enumerate(seq):
            column_list[i].append(nuc)
            ddd = column_list
    print ddd

tt = ["".join(y for y in x if y in {'A','G','T','C'}) for x in ddd]
print tt
</code></pre>

<p>You can first create a helper function:</p>

<pre><code>def filterJoin(s):
    return ''.join(x for x in s if x in 'ATGC')
</code></pre>

<p>Then:</p>

<pre><code>&gt;&gt;&gt; sample = [['A','T','N','N'],['T', 'C', 'C', 'C']],[['A','T','T','N'],['T', 'T', 'C', 'C']]
&gt;&gt;&gt; [[filterJoin(s) for s in t] for t in sample]
[['AT', 'TCCC'], ['ATT', 'TTCC']]
</code></pre>

python list