From the course: Python Data Structures: Dictionaries

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Implementation of dictionaries as hash tables in Python

Implementation of dictionaries as hash tables in Python - Python Tutorial

From the course: Python Data Structures: Dictionaries

Start my 1-month free trial

Implementation of dictionaries as hash tables in Python

- [Instructor] One of the most valued data structure is the dictionary data structure. A Python dictionary is highly optimized. Hash tables are the engines used to implement Python dictionaries. Hashing is a tried and a tested Table Lookup optimization and it is used everywhere in system software and databases, operating systems and compilers. A dict-hash table in Python is stored in memory as an array. It is a specialized kind of array called the sparse-table, that is, it always has empty cells. The goal of a hash table is to distribute the data evenly across the table. In Python, in the dictionary implementation, the goal is to keep at least one third of the hash table empty. If it gets too crowded, then it's copied to a new location with a larger size. This is primarily why it is not a good idea to modify a dictionary while iterating through it. If you need to scan and add items to a dictionary, do in two…

Contents