Why is the Python 3.3+ dict organizing not only undefined, but also a variable?

I ask this question out of curiosity (in particular, understanding how python works under the hood).

I fully understand that the python object is dictunordered - you can add a bunch of elements and print some view dict, and the ordering of the elements in the view will not correspond to the order being entered.

However, I wonder why the order changes from one code execution to the next?

I have a really simple python script that prints dictto the console. The dict type looks like this (content is pretty inappropriate):

{
    'hello': 'hi',
    'goodbye': 'bye',
    'hahaha': 'lol',
}

Printing on the console leads to the fact that the elements are not only printed in random order, but also printed in a different order each time the program starts . Here is my question: why is this so?

NOTE. The python code is inside the django project (but I do not use any django functions in this case - just mention it if it is anyway relevant).

+4
source share
1 answer

There is a note here: https://docs.python.org/3/reference/datamodel.html#object.__hash__

Here is a note:

.. __hash__() str, bytes datetime "" , Python, Python.    , , dict, O (n ^ 2). . http://www.ocert.org/advisories/ocert-2011-003.html.    dicts, . Python ( 32- 64- ).

     

. PYTHONHASHSEED.

3.3: .

+7

Source: https://habr.com/ru/post/1619398/