Skip to content
Python and Data Primer / Python Foundations

Collections

A program needs to know whether a price belongs to a date, a ticker or a position in a sequence. Python collections represent those different relationships. This lesson chooses among lists, tuples, dictionaries and sets, then explains copying and shared mutable data. These choices prepare you to load files and build labelled tables.
Learning objectives. By the end of this note you should be able to:
  • choose a collection from the relationship in the data;
  • index, slice and iterate over a sequence;
  • retrieve a value from a dictionary by key;
  • explain why mutating a list through one name can affect another.

In this lesson

  1. Four useful relationships
  2. Sequences preserve order
  3. Mappings make labels explicit
  4. Two names can share one list

Before you start

This lesson is part of a free topic. Create a free account, no card needed, to read it in full with worked examples and exercise solutions.

Read it free