8ORGANIZING VALUES USING SETS AND DICTIONARIES

image

A Python list is useful whenever we need to store a sequence of values, such as the heights of action figures or the words in an essay. Lists make it easy for us to keep values in order and access a value given its index. As we’ll see in this chapter, though, there are operations that lists are not optimized for, including identifying whether a specific value is in a collection and making associations between pairs of values.

In this chapter, we’ll learn about Python sets and dictionaries, two alternatives to lists for storing collections of values. We’ll see that a set can be the tool of choice when ...

Get Learn to Code by Solving Problems 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.