Dictionaries are ordered in Python 3.6
<p>Dictionaries are ordered in Python 3.6, unlike in previous Python incarnations. This seems like a substantial change, but it's only a short paragraph in the <a href="https://docs.python.org/3.6/whatsnew/3.6.html#other-language-changes">documentation</a>. It is described as an implementation detail rather than a language feature, but also implies this may become standard in the future.</p>

<p>How does the Python 3.6 dictionary implementation perform better than the older one while preserving element order? </p>

<p>Here is the text from the documentation:</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">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">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">issue 27350</a>. Idea <a href="https://mail.python.org/pipermail/python-dev/2012-December/123028.html">originally suggested by Raymond Hettinger</a>.)</p>
</blockquote>

<p>Below is answering the original first question:</p>

<blockquote>
  <p>Should I use <code>dict</code> or <code>OrderedDict</code> in Python 3.6?</p>
</blockquote>

<p>I think this sentence from the documentation is actually enough to answer your question</p>

<blockquote>
  <p>The order-preserving aspect of this new implementation is considered an implementation detail and should not be relied upon</p>
</blockquote>

<p><code>dict</code> is not explicitly meant to be an ordered collection, so if you want to stay consistent and not rely on a side effect of the new implementation you should stick with <code>OrderedDict</code>.</p>

<p>Make your code future proof :)</p>

<p>There's a debate about that <a href="https://news.ycombinator.com/item?id=12460936">here</a>.</p>

python python-3.x dictionary python-internals python-3.6