Summary

We've looked at three mutable collections: lists, sets and dictionaries. The built-in dictionary class is only one of many mappings available in Python, the others are defined in the collections module of the standard library. The list allows us to collect items which are identified by their positions in the list. The set allows us to collect a set of unique items, in which each item is simply identified by itself. A mapping allows us to identify items by a key.

For sets, each item must be immutable. For mappings, the object used as a key must be immutable. This means that numbers, strings, and tuples are often used as mapping keys.

We've looked at the for statement, which is the primary way we'll process the individual items in a collection. ...

Get Python Essentials 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.