Can't unpack list structure for nested list comprehension
<p>Having issues creating a simple nested list comprehension. Each level of unpacking doesn't properly remove the list from list structure. Detail below.</p>

<pre><code>file_list = ['genes1.csv', 'genes2.csv']

set_list = [('genes2.csv', (['A2LD1', 'A1BG', 'A2ML1', 'A1CF', 'A2M', 'A2BP1'], [-0.95, 1.226, 3.473, 4.958, 6.645, 11.953])), ('genes1.csv', (['A2LD1', 'A1BG', 'A2ML1', 'A1CF', 'A2M', 'A2BP1'], [-0.529, 1.444, 3.133, 4.303, 6.387, 11.117]))]

set_list.sort(key = lambda (x,y): file_list.index(x))
</code></pre>

<p>Let's look at the sorted set_list:</p>

<pre><code>print '\nset_list sorted:', set_list

set_list sorted: [('genes1.csv', (['A2LD1', 'A1BG', 'A2ML1', 'A1CF', 'A2M', 'A2BP1'], [-0.529, 1.444, 3.133, 4.303, 6.387, 11.117])), ('genes2.csv', (['A2LD1', 'A1BG', 'A2ML1', 'A1CF', 'A2M', 'A2BP1'], [-0.95, 1.226, 3.473, 4.958, 6.645, 11.953]))]
</code></pre>

<p>Now we're going to pull values only for sample 1, in this case, values from genes1.csv:</p>

<pre><code>sample_1_values = []
for i, (j, k) in set_list[:1]:
    for v in k:
        sample_1_values.append(v)

print '\nsample 1 values:', sample_1_values
</code></pre>

<p>And the output:</p>

<pre><code>sample 1 values: [-0.529, 1.444, 3.133, 4.303, 6.387, 11.117]
</code></pre>

<p>Now the aim is to create sample_1_values as a nested list comprehension:</p>

<pre><code>sample_1_values = [[v for v in k] for i, (j, k) in set_list[:1]]

print '\nsample_1_values from list comprehension:', sample_1_values
</code></pre>

<p>And the output:</p>

<pre><code>[[-0.529, 1.444, 3.133, 4.303, 6.387, 11.117]]
</code></pre>

<p>Let's break down the nesting structure, first:</p>

<pre><code>s_list_comp_1 = [k for i, (j, k) in set_list[:1]]

print '\ninner list comprehension:', s_list_comp_1
print type(s_list_comp_1)
</code></pre>

<p>Output:</p>

<pre><code>inner list comprehension: [[-0.529, 1.444, 3.133, 4.303, 6.387, 11.117]]
&lt;type 'list'&gt;
</code></pre>

<p>No unpacking has occurred. Now for the outer nesting:</p>

<pre><code>s_list_comp_2 = [v for v in s_list_comp_1]

print '\nouter list comprehension', s_list_comp_2
print type(s_list_comp_2)
</code></pre>

<p>Output:</p>

<pre><code>[[-0.529, 1.444, 3.133, 4.303, 6.387, 11.117]]
&lt;type 'list'&gt;
</code></pre>

<p>The same issue, the list hasn't been unpacked this time. With a for statement and append, we see it does properly:</p>

<pre><code>s_list_comp_2 = []
for v in s_list_comp_1:
    for l in v:
        s_list_comp_2.append(l)

print '\ncorrect unpacking:', s_list_comp_2
</code></pre>

<p>Output:</p>

<pre><code>correct unpacking: [-0.529, 1.444, 3.133, 4.303, 6.387, 11.117]
</code></pre>

<p>The correct unpacking takes another level of hierarchy which I can't replicate using a nested list comprehension. The entire expression creating sample_1_values must be a nexted list comprehension to insert in later without having this placeholder. Suggestions?</p>
