Get the App
SLTechnology News&Howtos  ›  Development  › 

An example Analysis of the principle of python ordered Dict

Shulou Source: shulou.com Published: 2022-06-03 17:41:39 10月14日 Update

This article mainly introduces the example analysis of python orderly Dict principle, which has certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let Xiaobian take you to understand it together.

After Python 3.7, Dict adopts a new data structure, so that the memory footprint of the new Dict is less than that of the old Dict.

2. The new Dict is consistent with the insertion order when traversing. The specific implementation is that initialization will generate two arrays. When inserting values, add the current data to array 2.

Get the index A where the currently added data is located, then hash the key modulo to calculate the index B, and finally update the value of the index B to A.

examples

#The initial structure # -1 represents that the data array_1 = [-1, -1,-1, -1, -1] array_2 = [] #After inserting the value, it will become:array_1 = [-1, 0, -1,-1, -1, -1] array_2 = [123456, "key1", 1], [234567, "key2", 2],] Thank you for reading this article carefully. I hope that Xiaobian will share the "example analysis of python ordered Dict principle" This article is helpful to everyone. At the same time, I hope everyone will support it a lot. Pay attention to the industry information channel. More relevant knowledge is waiting for you to learn!

Tags: Data article subscript order principle example analysis array structure consistency two representation value interest memory at the same time instance location data structure more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno vpn Shulou Technology MySQL Docker