Could we say that Dictionaries store data in memory similarly to a list sequence?
Thanks in advance for the clarification.
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.