Programming · Flagship experience

Choosing Python Collections

List, tuple, set or dictionary—what changes when you choose the wrong one?

Start here

List, tuple, set or dictionary—what changes when you choose the wrong one?

Collections encode assumptions about order, uniqueness, mutability and lookup. The right data structure makes intended operations obvious and accidental complexity harder.

Building interactive view…
Understand

Build the mental model

Collections encode assumptions about order, uniqueness, mutability and lookup. The right data structure makes intended operations obvious and accidental complexity harder. Choose by operations, not habit. If identity matters, use keys; if uniqueness matters, use sets; if order and repetition matter, use sequences.

Click a stage to inspect what happens, what changes, and what should be checked before moving on.
Stage 1

Operation needed

For the “Operation needed” stage, identify the incoming object, the rule applied to it, the state change produced, and the evidence that would reveal a mistake. Technical context for Choosing Python Collections: Lists provide ordered mutable sequences; tuples are ordered and immutable; sets optimise uniqueness/membership; dictionaries map keys to values with fast key-based lookup.

Practitioner checkpoint: Choose by operations, not habit. If identity matters, use keys; if uniqueness matters, use sets; if order and repetition matter, use sequences.
What happens if…?

Break the assumption deliberately

Replace a dictionary lookup with repeated list scanning and compare the mental and computational cost.

Move the control and explain what you expect before reading the visual.

Technical lens

Formalise what the visual is doing

Lists provide ordered mutable sequences; tuples are ordered and immutable; sets optimise uniqueness/membership; dictionaries map keys to values with fast key-based lookup.

Technical questionUse a tiny case to make the mechanism observable. Lists provide ordered mutable sequences; tuples are ordered and immutable; sets optimise uniqueness/membership; dictionaries map keys to values with fast key-based lookup. Verify one intermediate quantity, state change or mapping independently; then predict the consequence of this change: Replace a dictionary lookup with repeated list scanning and compare the mental and computational cost.
Practitioner lens

Use it responsibly

Choose by operations, not habit. If identity matters, use keys; if uniqueness matters, use sets; if order and repetition matter, use sequences.

Transfer testUsing a list for repeated membership tests when a set is more appropriate.
Worked exploration

Use the visual as an experiment, not decoration

Store the same five values in a list, set and dictionary. Observe that the list preserves order and duplicates, the set removes duplicates and supports membership, and the dictionary retrieves values by key.

Technical lens

Lists provide ordered mutable sequences; tuples are ordered and immutable; sets optimise uniqueness/membership; dictionaries map keys to values with fast key-based lookup.

Practitioner check

Choose by operations, not habit. If identity matters, use keys; if uniqueness matters, use sets; if order and repetition matter, use sequences.

Prediction before interaction
Replace a dictionary lookup with repeated list scanning and compare the mental and computational cost.
Exploration walkthrough

Turn the interaction into an evidence trail

Store the same five values in a list, set and dictionary. Observe that the list preserves order and duplicates, the set removes duplicates and supports membership, and the dictionary retrieves values by key. Before moving the control, state your prediction. After the visual changes, name the specific state, statistic, boundary or mapping that changed and explain why that change is consistent—or inconsistent—with your prediction.

  • Record one observable quantity before the interaction and the same quantity afterwards.
  • Change one factor at a time so the causal effect of the control is inspectable.
  • Use an edge or failure case to discover where the concept stops behaving as the simple story suggests.
Reference depth

Open the complete material

The flagship experience is the map. These pages contain the roads.

Deep Learning Hub lessons

Lists, dictionaries and arraysPython, Notebooks & Reproducible AnalysisPython objects and variablesPython, Notebooks & Reproducible Analysis

Related models & simulations

Use the Concept Atlas for related methods and adjacent concepts.

Continue this exact concept

Choose depth, practice or application.

These destinations are explicitly mapped to Choosing Python Collections; they are not generic landing-page fallbacks.