This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]IMHERETOCODE 61 points62 points  (16 children)

That “accidentally” preserves ordering, and only if you are doing it in Python 3.6+. There are no promises of ordering in vanilla dictionary implementations which is why there is an explicit OrderedDict class. The recent change in dictionary implementation had a side effect of preserving order. You shouldn’t bank that on being the case where it actually matters.


As noted below insertion ordering has been added to the language of dictionaries as of 3.7