Since when builtin dict preserve key order?

Chris Angelico rosuav at gmail.com
Sat Mar 24 05:14:02 EDT 2018


On Sat, Mar 24, 2018 at 7:48 PM, Marko Rauhamaa <marko at pacujo.net> wrote:
> Chris Angelico <rosuav at gmail.com>:
>
>> On Sat, Mar 24, 2018 at 3:34 PM, Arkadiusz Bulski
>> <arek.bulski at gmail.com> wrote:
>>> I already asked on PYPY and they confirmed that any version of pypy,
>>> including 2.7, has dict preserving insertion order. I am familiar
>>> with ordered **kw which was introduced in 3.6 but I also heard that
>>> builtin dict preserves order since 3.5. Is that true?
>>>
>>
>> I don't think 3.5 had it. According to the tracker, it landed in 3.6:
>>
>> https://bugs.python.org/issue27350
>>
>> But yes, current versions of CPython preserve insertion order.
>
> Is that part of the Python Language Specification? If not, it shouldn't
> be exploited in application programs.
>

Yes, it is; but the language spec wasn't locked in quite as soon as
the functionality was. So you may find that CPython 3.6 preserves
order more than the language requires. Starting with 3.7 (I believe),
the language spec is significantly tighter.

ChrisA



More information about the Python-list mailing list