title: Why is dictionary ordering non-deterministic?
body: <p>I recently switched from Python 2.7 to Python 3.3, and it seems that while in Python 2 the ordering of dictionary keys was arbitrary but consistent, in Python 3 the ordering of the keys of a dictionary obtained with e.g. <a href="https://docs.python.org/3/library/functions.html#vars" rel="noreferrer"><code>vars()</code></a> appears non-deterministic.</p>
  
  <p>If I run:</p>
  
  <pre><code>class Test(object): pass
  parameters = vars(Test)
  print(list(parameters.keys()))
  </code></pre>
  
  <p>in both Python 2.7 and Python 3.3, then:</p>
  
  <ul>
  <li><p>Python 2.7 consistently gives me</p>
  
  <pre><code>['__dict__', '__module__', '__weakref__', '__doc__']
  </code></pre></li>
  <li><p>With Python 3.3, I can get any random order – for example:</p>
  
  <pre><code>['__weakref__', '__module__', '__qualname__', '__doc__', '__dict__']
  ['__doc__', '__dict__', '__qualname__', '__module__', '__weakref__']
  ['__dict__', '__module__', '__qualname__', '__weakref__', '__doc__']
  ['__weakref__', '__doc__', '__qualname__', '__dict__', '__module__']
  </code></pre></li>
  </ul>
  
  <p>Where does this non-determinism come from? And why is something like</p>
  
  <pre><code>list({str(i): i for i in range(10)}.keys())
  </code></pre>
  
  <p>… consistent between runs, always giving</p>
  
  <pre><code>['3', '2', '1', '0', '7', '6', '5', '4', '9', '8']
  </code></pre>
  
  <p>… ?</p>