4 Dictionaries and sets
Dictionaries (http://mng.bz/5aAz), or dicts, are one of Python’s most powerful and important data structures. You may recognize them from other programming languages, in which they can be known as “hashes,” “associative arrays,” “hash maps,” or “hash tables.”
In a dict, we don’t enter individual elements, as in a list or tuple. Rather, we enter pairs of data, with the first item known as the key and the second item known as the value. Whereas the index in a string, list, or tuple is always an integer, and always starts with 0, dict keys can come from a wide variety of Python types--typically integers or strings.
This seemingly small difference, that we can use arbitrary keys to locate our values, rather than using integer ...
Get Python Workout 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.