4
Dictionaries
A natural complement to lists and sequences in Python is the dictionary type, which stores lookup keys mapped to corresponding values (in what is often called an associative array or a hash table). Their versatility makes dictionaries ideal for bookkeeping: dynamically keeping track of new and changing pieces of data and how they relate to each other. When writing a new program, using dictionaries is a great way to start before you're sure what other data structures or classes you might need.
Dictionaries provide constant time (amortized) performance for adding and removing items, which is far better than what simple lists can achieve on their own. Thus, it's understandable that dictionaries are the core data structure that Python ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access