Python: how to dump the values of a dict to a list respecting the original visualization?
<p>I need to dump the values of a <code>dict</code> to a <code>list</code>. In doing this, I want to preserve the sorting given when the <code>dict</code> is visualized.</p>

<p>Example. This is my dict:</p>

<p><code>mydict={10: 0,
 20: 0,
 30: 0,
 40: 0,
 50: 1.0,
 60: 0,
 70: 1.0,
 80: 0.825,
 90: 0.916,
 100: 0.102}</code></p>

<p>I dump its values to a list like this:</p>

<p><code>y = mydict.values()</code></p>

<p>But when I visualize such list, this is what I get:</p>

<pre><code>In[1]: y
Out[1]: [0.102, 1.0, 0, 0, 0.825, 1.0, 0, 0.916, 0, 0]
</code></pre>

<p>What can I do to make sure my list stores the values in the exact order shown by the dict? I want to have:</p>

<pre><code>In[1]: y
Out[1]: [0, 0, 0, 0, 1.0, 0, 1.0, 0.825, 0.916, 0.102]
</code></pre>

<p><strong>EDIT</strong></p>

<p>If I use an <code>OrderedDict</code> while building my dict, the problem remains. My dict in this case would simply be visualized like this:</p>

<pre><code>In[2]: mydict
Out[2]: OrderedDict([(100, 0.102), (70, 1.0), (40, 0), (10, 0), (80, 0.825), (50, 1.0), (20, 0), (90, 0.916), (60, 0), (30, 0)]
</code></pre>

<p>And <code>y</code> would still be the same as before:</p>

<pre><code>In[3]: y
Out[3]: [0.102, 1.0, 0, 0, 0.825, 1.0, 0, 0.916, 0, 0]
</code></pre>