Are dictionaries ordered in Python 3.6+?
<p>Dictionaries are insertion ordered as of Python 3.6. It is described as a CPython implementation detail rather than a language feature. The <a href="https://docs.python.org/3.6/whatsnew/3.6.html#new-dict-implementation" rel="noreferrer">documentation</a> states:</p>
<blockquote>
<p><code>dict()</code> now uses a “compact” representation <a href="https://morepypy.blogspot.com/2015/01/faster-more-memory-efficient-and-more.html" rel="noreferrer">pioneered by PyPy</a>. The memory usage of the new dict() is between 20% and 25% smaller compared to Python 3.5. <a href="https://www.python.org/dev/peps/pep-0468" rel="noreferrer">PEP 468</a> (Preserving the order of **kwargs in a function.) is implemented by this. The order-preserving aspect of this new implementation is considered an implementation detail and should not be relied upon (this may change in the future, but it is desired to have this new dict implementation in the language for a few releases before changing the language spec to mandate order-preserving semantics for all current and future Python implementations; this also helps preserve backwards-compatibility with older versions of the language where random iteration order is still in effect, e.g. Python 3.5). (Contributed by INADA Naoki in <a href="https://bugs.python.org/issue27350" rel="noreferrer">issue 27350</a>. Idea <a href="https://mail.python.org/pipermail/python-dev/2012-December/123028.html" rel="noreferrer">originally suggested by Raymond Hettinger</a>.)</p>
</blockquote>
<p>How does the new dictionary implementation perform better than the older one while preserving element order?</p>
<hr />
<p>Update December 2017: <code>dict</code>s retaining insertion order is <a href="https://mail.python.org/pipermail/python-dev/2017-December/151283.html" rel="noreferrer">guaranteed</a> for Python 3.7</p>