Pythonity Blog Pythonity Blog

In Python 3.6 regular dicts are ordered and more compact

Busy times at the company so no long form post today, but I wanted to pass along this and this, as I found both the news and the discussion worthwhile.

Couple of my favorite comments:

"ordered" means "insertion order". For a sorted dict see the excellent sortedcontainers module. This provides dicts, lists, and sets that return keys in sequence (including, you can supply a key() func for custom sorting), and maintain the sequence under deletions and insertions, with low overhead. This functionality is still not in the std library.


This update broke my workflow! I was using dictionaries for an additional source of entropy in my RNG, and now I'll have to start over again.


Ordered dicts are a CPython implementation detail, and are not specified or guaranteed to be consistent across other forms of Python (although they will be ordered in PyPy as well). On the other hand, OrderedDict is always guaranteed to be ordered. On CPython, when you ask for an OrderedDict, what you're getting will essentially be a thin wrapper around dict with a few extra methods, so you should still have the speed of a native dict.


(...) dicts are not guaranteed to be ordered, but - keyword args are ordered - the namespace passed to a metaclass is ordered by definition order - ditto for the class dict A compliant implementation may ensure the above three requirements either by making all dicts ordered, or by providing a custom dict subclass (e.g. OrderedDict) in those three cases.


If you want to play with the newest release, Python 3.6.0 beta 1 is now available.