I have a nested list, but i want to add a nested list inside the nested list
<p>I have a list like:</p>

<pre><code>[[21, 32, 32], [23, 34, 32], [32, 34, 57]]
</code></pre>

<p>I would like to convert each number to its own list like</p>

<pre><code>[[[21], [32], [32]], [[23], [34], [32]], [[32], [34], [57]]]
</code></pre>

<p>How would i do that?</p>

<p>Thanks!</p>

<p>Use a <em>list comprehension</em>:</p>

<pre><code>&gt;&gt;&gt; lst = [[21, 32, 32], [23, 34, 32], [32, 34, 57]]
&gt;&gt;&gt; new_lst = [[[i] for i in sub_lst] for sub_lst in lst]
&gt;&gt;&gt; new_lst
[[[21], [32], [32]], [[23], [34], [32]], [[32], [34], [57]]]
</code></pre>

<hr>

<p>You can also use <code>numpy</code> by simply adding an extra axis using <a href="http://docs.scipy.org/doc/numpy-1.10.0/reference/arrays.indexing.html#numpy.newaxis" rel="nofollow"><code>np.newaxis</code></a> while <em>slicing</em> your array:</p>

<pre><code>&gt;&gt;&gt; import numpy as np
&gt;&gt;&gt; l = np.array([[21, 32, 32], [23, 34, 32], [32, 34, 57]])
&gt;&gt;&gt; l[:, :, np.newaxis] # or l[:, :, None]
array([[[21],
        [32],
        [32]],

       [[23],
        [34],
        [32]],

       [[32],
        [34],
        [57]]])
</code></pre>

python python-3.x