Unit 3 · Programming 2 · Lesson 3.6

Lists I: Many Values, One Name

Thirty test scores could mean thirty variables — or one list. Lists are how programs hold a whole collection under a single name, and they come with the second big flip of the unit.

Big Idea 3 — Algorithms & ProgrammingWeek 2 · Lists

Before this lesson — read on Runestone

Focus on creating a list and pulling a value out by index. Enrolled in our Runestone course? Open it from there so your progress counts.

1

Where We Are

People→ Bits→ Programs→ Internet→ Security→ Big Data→ Impact

Still in Programs, opening Week 2. Loops let you repeat an action; lists give you a collection to repeat it over. Together they’re the engine of almost every real program — and of the accumulator you just learned.

2

The Hook

score1, score2, score3, score4, score5… Imagine tracking a class of 30 with 30 separate variables. Now average them — you’d type all 30 names. Add a student and you rewrite everything. It’s absurd, and you can feel it.

A list fixes it: one name, scores, holding all the values in order. You reach any one by its position — its index — and you can loop over the whole thing at once. This is the tool that makes loops worth having.

3

The Idea

A list holds values in order. Each value is an element, and each element has an index — its position. You read an element with square brackets: scores[0].

The index flip — the second big flip of the unit. Python counts positions starting at 0: the first element is scores[0]. AP Pseudocode counts starting at 1: the first element is scores[1]. Same list, different position numbers. This appears in warm-ups every week from now on, because it is one of the two most-missed mechanical ideas on the exam.

Here is one list, labeled both ways at once — the picture to keep in your head:

value85907892
Python index0123
AP index1234

Python — 0-based

scores = [85, 90, 78, 92]
print(scores[0])   # 85 (first)
print(scores[2])   # 78
scores[1] = 100  # update

AP Pseudocode — 1-based

scores ← [85, 90, 78, 92]
DISPLAY(scores[1])   /* 85 (first) */
DISPLAY(scores[3])   /* 78 */
scores[2] ← 100  /* update */

Hover or tap a line to light its twin. Both grab the same elements — the first (85) and the third (78) — but the position numbers differ by one. Read the notation, then count from its starting point.

A list is data abstraction (the ladder returns). Back in 1.7 abstraction meant “one name hiding a lot of detail.” A list is exactly that: scores is a single name standing in for a whole collection, and you can pass it around, loop over it, or grow it without caring how it’s stored. Third rung of the same ladder.
4

Try It — The Index Machine

Click an element to see its Python index and its AP index side by side. Same box, two position numbers — burn the picture in.

click a value above
Python index: —
AP index: —
5

Vocabulary

list Programs
An ordered collection of values stored under one name.
element Programs
A single value inside a list.
index Programs
An element’s position. Python starts at 0; AP Pseudocode starts at 1.
data abstraction Programs
Using one name to represent a whole collection of values — hiding the individual pieces behind a single handle.
6

Check

Five questions. For each, write the list out and count from the right starting point (0 for Python, 1 for AP). Then pick your answer.

0 of 5 answered
7

Impact Check

Everything is a list underneath

Your playlist, your contacts, a feed of posts, search results, the high-score table, the frames of a video — all lists. The moment an app shows you “a bunch of things in order,” there’s a list behind it, and a loop walking through it. Lists are how software handles many instead of one.

The 0-vs-1 flip isn’t just an exam quirk, either. Real bugs come from “the first item” meaning index 0 to one programmer and index 1 to another. Whole categories of software errors are off-by-one mistakes at the edge of a list. Knowing exactly where counting starts is a professional habit.

8

Connections

Came from 1.7 — a list is data abstraction: one name hiding many values.
Next in 3.7 — lists can grow and shrink: append, remove, and building a list from user input inside a loop.
Returns in 3.8 — the real payoff: loop over every element at once with traversal.
Returns on the exam — index questions in both notations are guaranteed. Count from the starting point the notation uses, every time.
← 3.5 Lab: Loop Day