I'm asking this question out of curiosity (specifically, insight into how python is working under the hood).
I am fully aware that the python dict
object is unordered - you can put in a bunch of items, and print out some representation of the dict
, and the ordering of the items in the representation will have no correspondence to the order that the items were entered.
What I'm curious about, however, is why the ordering changes from one execution of the code to the next?
I have a really simple python script that is printing a dict
to the console. The dict looks like this (content is pretty irrelevant):
{
'hello': 'hi',
'goodbye': 'bye',
'hahaha': 'lol',
}
Printing it to the console causes the items to not only be printed in a random order, but to be printed in a different order each time I run the program. Here's my question: Why is this the case?
NOTE: The python code is inside a django project (but I'm not using any django functionality in this case - just mentioning this in case it's somehow relevant).