Review

Key Ideas

  • A list stores ordered values.
  • A tuple stores a small fixed group of values.
  • Unpacking gives tuple positions names.
  • A dictionary maps keys to values.
  • A set stores unique values and supports membership checks.
  • Indexing reads one item by position.
  • Slicing reads part of an ordered collection.
  • A comprehension builds a new collection from an existing one.
  • Mutation changes an object in place.
  • Copying makes a separate object.

Key Syntax

SyntaxMeaning
[8, 6, 9]list
(3, 4)tuple
x, y = pointunpacking
{"cat": 2}dictionary
{"cat", "dog"}set
scores[0]first item
scores[1:3]slice from index 1 up to 3
[n * 2 for n in values]list comprehension
items.copy()shallow list copy

Common Mistakes

MistakeFix
Using a list when a dictionary would make names cleareruse keys
Expecting range or slices to include the stop valueremember stop is excluded
Looking up a missing dictionary keycheck membership first
Assuming set order mattersuse a list if order matters
Writing a dense comprehensionuse a normal loop
Assuming b = a copies a listuse .copy()

Checklist

You are ready to move on if you can:

  • build and append to a list
  • unpack a two-item tuple
  • count values with a dictionary
  • use a set for uniqueness
  • read an item by index
  • explain a slice endpoint
  • write a simple list comprehension
  • predict a shared-list mutation

If You Feel Lost

Return to the four container questions:

  • Do I need order? Use a list.
  • Do I need a fixed small record? Use a tuple.
  • Do I need lookup by key? Use a dictionary.
  • Do I need uniqueness? Use a set.