python comprehension trubleshooting
<pre><code>base=2
digits=set(range(base))
key=range(base**3)
dict={ k:[a,b,c] for k in key for a in digits for b in digits for c in digits}
print(dict) 
</code></pre>

<p>the output is:</p>

<pre><code>{0: [1, 1, 1], 1: [1, 1, 1], 2: [1, 1, 1], 3: [1, 1, 1], 4: [1, 1, 1], 5: [1, 1, 1], 6: [1, 1, 1], 7: [1, 1, 1]}
</code></pre>

<p>I wonder why the output for [a,b,c] is [1,1,1], not the same as the:</p>

<pre><code>[[a,b,c] for a in digits for b in digits for c in digits]
</code></pre>

<p>which is:</p>

<pre><code>[[0, 0, 0], [0, 0, 1], [0, 1, 0], [0, 1, 1], [1, 0, 0], [1, 0, 1],[1,1,0], [1, 1, 1]]
</code></pre>

<p>We can simplify the dictionary comprehension to something like:</p>

<pre><code>In [728]: {k:[a,b] for k in [1,2] for a in [1,2] for b in [1,2]}
Out[728]: {1: [2, 2], 2: [2, 2]}
</code></pre>

<p>It is the equivalent to constructing a dictionary with nested loops:</p>

<pre><code>In [731]: d={}
In [732]: for k in [1,2]:
     ...:     for a in [1,2]:
     ...:         for b in [1,2]:
     ...:             d[k]=[a,b]
     ...:             
In [733]: d
Out[733]: {1: [2, 2], 2: [2, 2]}
</code></pre>

<p>But to clarify what is going, let's use a defaultdict, and append the new values:</p>

<pre><code>In [730]: from collections import defaultdict
In [734]: d=defaultdict(list)
In [735]: for k in [1,2]:
     ...:     for a in [1,2]:
     ...:         for b in [1,2]:
     ...:             d[k].append([a,b])
     ...:             
In [736]: d
Out[736]: 
defaultdict(list,
            {1: [[1, 1], [1, 2], [2, 1], [2, 2]],
             2: [[1, 1], [1, 2], [2, 1], [2, 2]]})
</code></pre>

<p>It is writing each <code>[a,b]</code> pair to the dictionary, but you only end up seeing the last pair for each key.</p>

<p>And yes, <code>@user2357112's</code> comprehension does the same thing</p>

<pre><code>In [737]: {k:[[a,b] for a in [1,2] for b in [1,2]] for k in [1,2]}
Out[737]: {1: [[1, 1], [1, 2], [2, 1], [2, 2]], 2: [[1, 1], [1, 2], [2, 1], [2, 2]]}
</code></pre>

python list-comprehension