Idiom for flattening a shallow nested list: how does it work?
<p>I found this bit of code in a module I am working on:</p>

<pre><code>l = opaque_function()
thingys = [x for y in l for x in y]
</code></pre>

<p>I can't read this. By experiment, I was able to determe that it is flattening a 2-level nested list, but the syntex is still opaque to me. It has obviously omitted some optional brackets.  </p>

<pre><code>&gt;&gt;&gt; l = [[1,2],[3,4]]
&gt;&gt;&gt; [x for y in l for x in y]
[1, 2, 3, 4]
</code></pre>

<p>My eyes want to parse it as either: <code>[x for y in [l for x in y] ]</code> or <code>[ [x for y in l] for x in y ]</code>, but both of those fail due to <code>y</code> not being defined. </p>

<p>How should I be reading this?</p>

<p>(I suspect I will feel very embarassed when this is explained.)</p>
