Last answered:

27 Jun 2023

Posted on:

16 Jun 2023

0

Could we say that Dictionaries store data in memory similarly to a list sequence?

Thanks in advance for the clarification.

1 answers ( 0 marked as helpful)
Instructor
Posted on:

27 Jun 2023

1

Hi  Panagiotis !
Thanks for reaching out.


A Python dictionary is an example of a hash table. The algorithm used to store and access keys in a hash table, along with their associated values, is designed to be very flexible and fast. It is flexible in that it allows a dictionary to contain keys of a wide variety of types.

The dictionary is stored in memory in the form of a hash table with an ordered array of ranges and their corresponding values. 

A list in Python is an array that contains elements pointers to objects of a specific size only and this is a common feature of all dynamically typed languages. For the implementation of a list a contiguous array of references to other objects is used. Python keeps a pointer to this array and the array’s length is stored in a list head structure. This makes indexing of a list independent of the size of the list or the value of the index. When items are appended or inserted the array of references is resized. 

So, in a nuthsell there is a difference in the way how dictionaries and lists are stored.


Hope this helps.
Best,
Tsvetelin

Submit an answer