How to make a list of lists in Python?
<p>Assume,</p>

<pre><code>range(len(column)) = 4
column = ['AAA', 'CTC', 'GTC', 'TTC']
for i in range(len(column)):
    a = list(column[i])
</code></pre>

<p>Outside of this loop I want a variable,say x to be assigned such that it gives the following output. </p>

<pre><code> ['A', 'A', 'A']
 ['C', 'T', 'C']
 ['G', 'T', 'C']
 ['T', 'T', 'C']
</code></pre>

<hr>

<p>After doing this, here is what I should be able to do:
In the Next, I want to compare within x. Say x[2] to tell me if 'G' is different from 'T' and if 'G' is different from 'C' and if 'T' is different from 'C'</p>

<p>You can easily create <code>x</code> without using <code>numpy</code> or other external module:</p>

<pre><code>column = ['AAA', 'CTC', 'GTC', 'TTC']
x = [list(column[i]) for i in range(len(column))]
print(x)
</code></pre>

<p>Output:</p>

<pre class="lang-none prettyprint-override"><code>[['A', 'A', 'A'], ['C', 'T', 'C'], ['G', 'T', 'C'], ['T', 'T', 'C']]
</code></pre>

<p>To use this you'll need to two indices: Which you can think of as the first representing the row and the second the column. For example the <code>'G'</code> is in <code>x[2][0]</code>. You can compare it to any other cell in <code>x</code> using the same notation.</p>

python python-2.7 for-loop return