Chapter 9. Sets and Dictionaries

If a word in the dictionary were misspelled, how would we know?

Steven Wright

Dictionaries are particularly useful key:value data structures, and you’ll see them used everywhere in Python. Sets are just bags of unique keys, anbd are also often vary handy.

Dictionaries

A dictionary is similar to a list, but the order of items doesn’t matter, and they aren’t selected by an offset such as 0 or 1. Instead, you specify a unique key to associate with each value. This key is often a string, but it can actually be any of Python’s immutable types: Boolean, integer, float, tuple, string, and others that you’ll see in later chapters. Dictionaries are mutable, so you can add, delete, and change their key-value elements. If you’ve worked with languages that support only arrays or lists, you’ll love dictionaries.

Note

In other languages, dictionaries might be called associative arrays, hashes, or hashmaps ...

Get Introducing Python, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.