Why Order of dictionary changed?

Screen Link: https://app.dataquest.io/m/314/dictionaries-and-frequency-tables/7/counting-with-dictionaries


In the above image initial assignment content rating data dictionary is in particular order{‘4+’,‘9+’,‘12+’,‘17+’} at line 1, Whereas the output of the same content rating dictionary in an different order{‘9+’,‘4+’‘12+’,‘17+’} at list line of output. What is the reason for this?


It’s me again :grinning:

This happened because the tutorial part of this mission screen was created in an earlier version of Python.

Now, in Python 3.7 and later versions, dictionaries are sorted by the order of item insertion. In earlier versions, they were unordered.

To check the current version of Python, run the following code:

import platform

You’ll get 3.8.2, i.e. a new (relatively) version of Python. While the previous version, when the tutorial was created, was older than 3.7.

1 Like

Hyy @Elena_Kosourova once again thanks a lot :smile: for sharing the knowledge.

1 Like