An in-depth session of 41 slides. It covers indexing from 0, negative indexes, and slicing with the end excluded, along with the slice shortcuts, joining with + and repeating with *, changing items, and append. The three misses the diagnostic found each appear as a trap slide, and there are five checks, followed by a scaffolded build-it-yourself Dream Team Roster project. It was built for the Pre-COSMOS Day 3 hour.
Subject: Python · 75 slides · code lesson
Open the interactive version of this deck · Homework for this lesson
Objectives
By the end of this hour you will be able to:
1. Grab any item out of a list using its index - counting from 0.
2. Slice a list to pull out exactly the items you want, and predict how many you get.
3. Join two lists with + and repeat a list with *.
4. Beat all three list questions from the diagnostic.
5. Build a Dream Team Roster program on your own.
Warm-up
Discussion prompt
Before we open Lists: Operations & Slicing: without looking back, what was the main idea of Data Types & Conversion, and what could you do by the end of it that you could not do before?
Hint: One sentence for the idea, one for the skill. If the second one is blank, that is the part to revisit.
Answer:
In-depth (40 slides): int/float/str/bool and type(); floats are approximate; // and %; input() always returns text; int()/float()/str() and f-strings; round() vs int() truncation; bool() truthiness; two build-it calculators; five checks. The three classic misconceptions are trap slides.
Concept
Sensor readings, color channels, and motor commands almost always travel in lists - a robot is basically a machine that reads lists and writes lists.
| Robot thing | What it looks like |
|---|---|
| 5 distance readings | [34, 36, 35, 90, 88] |
| One pixel's color | [255, 120, 0] |
| Motor speeds | [50, 50] (left, right) |
The diagnostic had three list questions - by the end of today you will be able to answer all three without guessing.
Comparison
Comparison matrix
From Why lists matter at camp: refill the What it looks like column from what you know. The rest of the table is as it appeared.
| Robot thing | What it looks like |
|---|---|
| 5 distance readings | [34, 36, 35, 90, 88] |
| One pixel's color | [255, 120, 0] |
| Motor speeds | [50, 50] (left, right) |
Concept
list — An ordered collection of values, written between square brackets and separated by commas.
[10, 20, 30, 40] is a list of four numbers. ["Bolt", "Ace"] is a list of two strings. Order matters - the list remembers exactly where everything sits.
Counterexample
Discussion prompt
[10, 20, 30, 40] is a list of four numbers. ["Bolt", "Ace"] is a list of two strings. Order matters - the list remembers exactly where everything sits.
That is stated as though it always holds. Do one of two things: produce a case where it fails, or say precisely what rules such a case out. "It just does" is not on the menu.
Hint: Hunt at the extremes first — zero, one, negative, empty, equal. If every extreme survives, the reason they survive is the proof.
Worked example
squad = ["Bolt", "Ace", "Nova", "Rex", "Zap", "Pixel"]
print(squad)
print(len(squad))Build the list with square brackets
Why: Six names, separated by commas, all stored in one variable called squad - one box holding six things in order.
Ask len() how many items it holds
Why: len() counts the items - it is the same len() that counted characters in a string.
| line | what prints |
|---|---|
| print(squad) | ['Bolt', 'Ace', 'Nova', 'Rex', 'Zap', 'Pixel'] |
| print(len(squad)) | 6 |
Intuition
Picture the squad in a row of lockers. Python paints a number on every locker - but the painter starts at 0, not 1.
Figure (svg): Six lockers labeled Bolt, Ace, Nova, Rex, Zap, Pixel with index numbers 0 through 5 painted underneath
So in a list of 6 items the indexes run 0 to 5. There is no locker 6 - asking for it is an error.
Analogy
Discussion prompt
Explain Lockers numbered from 0 by analogy to something with no Python in it at all — a queue, a recipe, a map, a bank balance, whatever fits. Then say where your analogy breaks.
Hint: An analogy that never breaks is not an analogy, it is the same idea wearing a hat. Find the seam — that is the part that is actually new.
Answer:
Picture the squad in a row of lockers. Python paints a number on every locker - but the painter starts at 0, not 1.
Concept
index — An item's position number in a list, starting from 0. Written in square brackets after the list's name: squad[0].
squad[0] is the first item. squad[1] is the second. The number in brackets is the locker number, not the count.
Explain it
Discussion prompt
Explain Indexing: grab one item to a student a year behind you. No notation, no jargon they have not met — and it still has to be true.
Hint: If your explanation needs a symbol they have never seen, you are describing the notation rather than the idea.
Answer:
squad[0] is the first item. squad[1] is the second. The number in brackets is the locker number, not the count.
Ranking
Put in order
Put the moves of Grabbing heroes by index into the order they have to happen.
Why: These are the moves of the worked example in the order it makes them, and each one is set up by the one before it. Count lockers 0, 1, 2 - that lands on Nova, the THIRD hero.
Worked example
squad = ["Bolt", "Ace", "Nova", "Rex", "Zap", "Pixel"]
print(squad[0])
print(squad[2])
print(squad[5])Read squad[0]
Why: Index 0 is the first locker - Bolt.
| expression | locker | value |
|---|---|---|
| squad[0] | 0 | Bolt |
Read squad[2]
Why: Count lockers 0, 1, 2 - that lands on Nova, the THIRD hero.
| expression | locker | value |
|---|---|---|
| squad[0] | 0 | Bolt |
| squad[2] | 2 | Nova |
Read squad[5]
Why: 5 is the last valid locker in a 6-item list - Pixel.
| expression | locker | value |
|---|---|---|
| squad[0] | 0 | Bolt |
| squad[2] | 2 | Nova |
| squad[5] | 5 | Pixel |
Trade off
Comparison matrix
From Grabbing heroes by index: every row here is a choice with a cost. Fill the locker column, then say which row you would actually pick and what you give up for it.
| expression | locker | value |
|---|---|---|
| squad[0] | 0 | Bolt |
| squad[2] | 2 | Nova |
Anomaly
Predict first
A student writes this, and it looks reasonable:
"I want the first hero, so I write squad[1]."
It is wrong. Say what breaks — and say it before you turn the page.
Correct: Feels right - first item, number 1.
"The painter started at 0, so the first locker is squad[0]."
Why: Feels right - first item, number 1. But Python hands back Ace, the second hero.
Trap
"I want the first hero, so I write squad[1]."
Read squad[1] expecting Bolt
Why: Feels right - first item, number 1. But Python hands back Ace, the second hero.
"The painter started at 0, so the first locker is squad[0]."
Read squad[0] to get Bolt
Why: Index = how many steps FROM the start. The first item is zero steps away.
Concept
Python also numbers lockers from the back: squad[-1] is the last item, squad[-2] the second-to-last.
Handy when you do not know how long the list is - the newest sensor reading is always readings[-1].
Worked example
squad = ["Bolt", "Ace", "Nova", "Rex", "Zap", "Pixel"]
print(squad[-1])
print(squad[-2])Read squad[-1]
Why: -1 means one step back from the end - Pixel.
Read squad[-2]
Why: -2 is two steps back - Zap.
| expression | value |
|---|---|
| squad[-1] | Pixel |
| squad[-2] | Zap |
Blank canvas
Draw it
Draw what The last hero, no counting needed just did — the shape of it, not the line-by-line working. One picture, labels only where you need them. Then check it against the steps: anything you could not draw is a step you followed rather than understood.
Concept
A 6-item list has lockers 0-5. Asking for squad[6] crashes with IndexError: list index out of range.
Rule of thumb: the biggest valid index is always len(list) - 1.
Concept
slice — list[start:end] - a NEW list containing the items from index start up to, but NOT including, index end.
nums[1:3] says: start at locker 1, stop before locker 3. The end index is where you stop - it never comes along.
Picture it
Figure (svg): Four boxes holding 10, 20, 30, 40 with cut positions 0 to 4 marked between them; dashed cuts at positions 1 and 3 keep the boxes holding 20 and 30
Discussion prompt
Read the picture before the words. What is this showing, and what is the one thing it is built to make obvious? Commit to an answer, then read on.
Hint: Name the parts, then say what changes between them — and if nothing changes, say what is being held still.
Answer:
Do not point at lockers - point at the gaps between them. A slice makes two cuts and keeps what is in the middle.
Intuition
Do not point at lockers - point at the gaps between them. A slice makes two cuts and keeps what is in the middle.
Figure (svg): Four boxes holding 10, 20, 30, 40 with cut positions 0 to 4 marked between them; dashed cuts at positions 1 and 3 keep the boxes holding 20 and 30
Bonus: the number of items you get is just end minus start. [1:3] gives 3 - 1 = 2 items.
Pattern
Predict first
The table runs: print(nums[0]) | 10 | single item at locker 0 · print(nums[1:3]) | [20, 30] | indexes 1 and 2 - end excluded
In Tracing nums[1:3], given the rows so far: what is the next one — the row where line is items in the slice?
Correct: items in the slice | 2 | 3 - 1 = 2
| line | what prints | why |
|---|---|---|
| print(nums[0]) | 10 | single item at locker 0 |
| print(nums[1:3]) | [20, 30] | indexes 1 and 2 - end excluded |
| items in the slice | 2 | 3 - 1 = 2 |
Why: The relationship between the columns, not the individual numbers, is what generates the next row. Plain index - locker 0 holds 10.
Worked example
nums = [10, 20, 30, 40]
print(nums[0])
print(nums[1:3])Read nums[0]
Why: Plain index - locker 0 holds 10. No brackets in the output: one item, not a list.
| index | 0 | 1 | 2 | 3 |
|---|---|---|---|---|
| value | 10 | 20 | 30 | 40 |
Slice nums[1:3]
Why: Start at index 1 (the 20), stop BEFORE index 3 (the 40). Items 1 and 2 come along - the 40 stays behind.
| line | what prints | why |
|---|---|---|
| print(nums[0]) | 10 | single item at locker 0 |
| print(nums[1:3]) | [20, 30] | indexes 1 and 2 - end excluded |
| items in the slice | 2 | 3 - 1 = 2 |
Error analysis
Annotate
Walk the callouts on Tracing nums[1:3]. Each one is a place this is easy to get subtly wrong.
Anomaly
Predict first
A student writes this, and it looks reasonable:
"nums[1:3] means items 1 through 3, so I get [20, 30, 40] - three items."
It is wrong. Say what breaks — and say it before you turn the page.
Correct: Reads like a range of lockers from 1 to 3 - but Python stops at the second cut, and 40 never makes it in.
"nums[1:3] means start at 1, stop BEFORE 3 - so I get [20, 30] - two items."
Why: Reads like a range of lockers from 1 to 3 - but Python stops at the second cut, and 40 never makes it in.
Trap
"nums[1:3] means items 1 through 3, so I get [20, 30, 40] - three items."
Expect indexes 1, 2 AND 3
Why: Reads like a range of lockers from 1 to 3 - but Python stops at the second cut, and 40 never makes it in.
"nums[1:3] means start at 1, stop BEFORE 3 - so I get [20, 30] - two items."
Take indexes 1 and 2 only
Why: The end number is the stop sign, not a passenger. Count check: 3 - 1 = 2 items.
Break the constraint
Discussion prompt
The rule this trap just fixed:
The end number is the stop sign, not a passenger. Count check: 3 - 1 = 2 items.
Now break it on purpose. Build a case that violates it and follow the consequences until something visibly fails. Where does the failure first show up — and would you have noticed it if you had not been looking?
Hint: The dangerous rules are the ones whose violation still produces an answer. If yours fails loudly, try to find one that fails quietly.
Answer:
Reads like a range of lockers from 1 to 3 - but Python stops at the second cut, and 40 never makes it in.
Concept
Leave out the start and Python uses the very beginning: squad[:3]. Leave out the end and it runs to the very end: squad[3:].
squad[:] (both blank) copies the whole list. Read [:3] out loud as "the first three."
Worked example
squad = ["Bolt", "Ace", "Nova", "Rex", "Zap", "Pixel"]
print(squad[:3])
print(squad[3:])Slice squad[:3]
Why: Blank start = from the beginning. Stop before 3: indexes 0, 1, 2 - the first three.
Slice squad[3:]
Why: Start at 3, blank end = all the way to the last item: indexes 3, 4, 5.
| expression | result |
|---|---|
| squad[:3] | ['Bolt', 'Ace', 'Nova'] |
| squad[3:] | ['Rex', 'Zap', 'Pixel'] |
| together | the whole squad, split in two |
Blank canvas
Draw it
Draw what Shortcuts in action just did — the shape of it, not the line-by-line working. One picture, labels only where you need them. Then check it against the steps: anything you could not draw is a step you followed rather than understood.
Concept
concatenation — Gluing two lists end-to-end with + to make one NEW, longer list.
[1, 2] + [3] is [1, 2, 3]. Same + you used on strings: "ab" + "c" glued text, this glues lists. It never does math on what is inside.
Fill the middle
Fill in the blanks
From Merging two squads — one line has had its right-hand side removed. Put it back.
squad = ["Bolt", "Ace", "Nova", "Rex", "Zap", "Pixel"]
squad2 = ["Turbo", "Glitch"]
team = squad + squad2
print(team)
print(len(team))
Why: team is what everything below it consumes, so the wrong expression here fails later and somewhere else. All six originals first, then the two recruits, in order - a brand-new 8-item list.
Worked example
squad = ["Bolt", "Ace", "Nova", "Rex", "Zap", "Pixel"]
squad2 = ["Turbo", "Glitch"]
team = squad + squad2
print(team)
print(len(team))Glue squad and squad2 with +
Why: All six originals first, then the two recruits, in order - a brand-new 8-item list.
Count the merged team
Why: 6 + 2 = 8. Joining lists adds their LENGTHS, never the items inside.
| line | what prints |
|---|---|
| print(team) | ['Bolt', 'Ace', 'Nova', 'Rex', 'Zap', 'Pixel', 'Turbo', 'Glitch'] |
| print(len(team)) | 8 |
Error analysis
Annotate
Walk the callouts on Merging two squads. Each one is a place this is easy to get subtly wrong.
Anomaly
Predict first
A student writes this, and it looks reasonable:
"Plus means add, so [1, 2] + [3] is 1 + 2 + 3 = 6."
It is wrong. Say what breaks — and say it before you turn the page.
Correct: That is what + does to plain numbers - but these are lists, and + never opens the boxes to do math.
"These are lists, so + glues them: [1, 2] + [3] is [1, 2, 3]."
Why: That is what + does to plain numbers - but these are lists, and + never opens the boxes to do math.
Trap
"Plus means add, so [1, 2] + [3] is 1 + 2 + 3 = 6."
Add up everything inside
Why: That is what + does to plain numbers - but these are lists, and + never opens the boxes to do math.
"These are lists, so + glues them: [1, 2] + [3] is [1, 2, 3]."
Join the lists end-to-end
Why: A 2-item list plus a 1-item list = a 3-item list. The items just line up; nothing gets added together.
Concept
[0] * 3 is [0, 0, 0] - the list stamped out three times, not multiplication on the 0.
Robots use this to start clean: [0] * 8 makes eight zeroed-out sensor slots in one line.
Pattern
Predict first
The table runs: ["Go!"] * 3 | ['Go!', 'Go!', 'Go!'] · [1, 2] * 2 | [1, 2, 1, 2]
In The chant builder, given the rows so far: what is the next one — the row where expression is **[0] * 3**?
Correct: [0] * 3 | [0, 0, 0]
| expression | result |
|---|---|
| ["Go!"] * 3 | ['Go!', 'Go!', 'Go!'] |
| [1, 2] * 2 | [1, 2, 1, 2] |
| [0] * 3 | [0, 0, 0] |
Why: The relationship between the columns, not the individual numbers, is what generates the next row. One copy, two copies, three copies, glued into a single list of 3 items.
Worked example
chant = ["Go!"] * 3
print(chant)
print([1, 2] * 2)Stamp ["Go!"] three times
Why: One copy, two copies, three copies, glued into a single list of 3 items.
Stamp [1, 2] twice
Why: The WHOLE pattern repeats: 1, 2, then 1, 2 again. No number ever gets doubled.
| expression | result |
|---|---|
| ["Go!"] * 3 | ['Go!', 'Go!', 'Go!'] |
| [1, 2] * 2 | [1, 2, 1, 2] |
| [0] * 3 | [0, 0, 0] |
Comparison
Comparison matrix
From The chant builder: refill the result column from what you know. The rest of the table is as it appeared.
| expression | result |
|---|---|
| ["Go!"] * 3 | ['Go!', 'Go!', 'Go!'] |
| [1, 2] * 2 | [1, 2, 1, 2] |
| [0] * 3 | [0, 0, 0] |
Anomaly
Predict first
A student writes this, and it looks reasonable:
"Times 3 multiplies, so [0] * 3 is [0]... and [1, 2] * 2 must be [2, 4]."
It is wrong. Say what breaks — and say it before you turn the page.
Correct: Feels like math class - but * on a list never touches the numbers inside the brackets.
"* copies the whole list: [0] * 3 is [0, 0, 0] and [1, 2] * 2 is [1, 2, 1, 2]."
Why: Feels like math class - but * on a list never touches the numbers inside the brackets.
Trap
"Times 3 multiplies, so [0] * 3 is [0]... and [1, 2] * 2 must be [2, 4]."
Multiply each number inside
Why: Feels like math class - but * on a list never touches the numbers inside the brackets.
"* copies the whole list: [0] * 3 is [0, 0, 0] and [1, 2] * 2 is [1, 2, 1, 2]."
Repeat the whole list that many times
Why: It is a rubber stamp: 3 stamps of [0] leave three 0s on the page. The length multiplies, the values never change.
Two truths and a lie
Sort into buckets
Some of these hold up and some are the exact mistakes this lesson is built to prevent. Sort them.
[10, 20, 30, 40] is a list of four numbers. ["Bolt", "Ace"] is a list of two strings. Order matters - the list remembers exactly where everything sits.; Picture the squad in a row of lockers. Python paints a number on every locker - but the painter starts at 0, not 1.squad[1]."; "nums[1:3] means items 1 through 3, so I get [20, 30, 40] - three items."Concept
Assign straight into a locker: squad[1] = "Comet" throws out whoever was at index 1 and puts Comet there.
This is a big difference from strings - you cannot do "team"[0] = "T", but you CAN rewrite a list.
Explain it
Discussion prompt
Explain Lists can change: swap an item to a student a year behind you. No notation, no jargon they have not met — and it still has to be true.
Hint: If your explanation needs a symbol they have never seen, you are describing the notation rather than the idea.
Answer:
Assign straight into a locker: squad[1] = "Comet" throws out whoever was at index 1 and puts Comet there.
Fill the middle
Fill in the blanks
From Trading Ace for Comet — one line has had its right-hand side removed. Put it back.
squad = ["Bolt", "Ace", "Nova", "Rex", "Zap", "Pixel"]
squad[1] = "Comet"
print(squad)
Why: squad[1] is what everything below it consumes, so the wrong expression here fails later and somewhere else. Index 1 held Ace; the assignment replaces just that one slot, everyone else stays put.
Worked example
squad = ["Bolt", "Ace", "Nova", "Rex", "Zap", "Pixel"]
squad[1] = "Comet"
print(squad)Assign Comet into locker 1
Why: Index 1 held Ace; the assignment replaces just that one slot, everyone else stays put.
| 0 | 1 | 2 | 3 | 4 | 5 | |
|---|---|---|---|---|---|---|
| before | Bolt | Ace | Nova | Rex | Zap | Pixel |
| after | Bolt | Comet | Nova | Rex | Zap | Pixel |
Concept
append — list.append(item) adds one item to the END of the list, in place - the list itself gets longer.
+ builds a new list; append stretches the same list. For adding one recruit at a time, append is the move.
Matching
Match the pairs
Match each term to the definition this lesson gave it — not the one you would guess from the word.
Why: These are the working definitions of list, index, slice, concatenation, append as Lists: Operations & Slicing uses them. Pairing them correctly is the test of whether you could state each one with the slide switched off.
Worked example
squad = ["Bolt", "Comet", "Nova", "Rex", "Zap", "Pixel"]
squad.append("Vortex")
print(squad)
print(len(squad))Append Vortex to the squad
Why: Vortex lands in a brand-new locker 6 at the end; nobody else moves.
| line | what prints |
|---|---|
| print(squad) | ['Bolt', 'Comet', 'Nova', 'Rex', 'Zap', 'Pixel', 'Vortex'] |
| print(len(squad)) | 7 |
Pattern
Everything from this hour fits on one card:
| # | you want | you write | remember |
|---|---|---|---|
| 1 | one item | squad[i] | first item is squad[0] |
| 2 | the last item | squad[-1] | negatives count from the back |
| 3 | a chunk | squad[start:end] | end is EXCLUDED; count = end - start |
| 4 | the first three | squad[:3] | blank start = from the beginning |
| 5 | everything after | squad[3:] | blank end = to the very end |
| 6 | join two lists | a + b | glues, never adds the insides |
| 7 | repeat a list | a * n | stamps the whole list n times |
| 8 | swap an item | squad[i] = new | rewrites one locker |
| 9 | add one at the end | squad.append(x) | same list, one longer |
Real world
Discussion prompt
Outside this lesson: where does Lists: Operations & Slicing actually turn up? Name one concrete situation — a job, a piece of software someone ships, a decision somebody has to make — and say which part of The list toolbox is doing the work in it.
Hint: Vague is the failure mode here. "Engineering" is not a situation; "deciding whether this build is fast enough to ship" is.
Answer:
An in-depth session of 41 slides. It covers indexing from 0, negative indexes, and slicing with the end excluded, along with the slice shortcuts, joining with + and repeating with *, changing items, and append. The three misses the diagnostic found each appear as a trap slide, and there are five checks, followed by a scaffolded build-it-yourself Dream Team Roster project. It was built for the Pre-COSMOS Day 3 hour.
Check
squad is ["Bolt", "Ace", "Nova", "Rex", "Zap", "Pixel"]. Decide before you click.
Check your understanding
What does print(squad[1]) show?
Answer: B
Why: Indexes start at 0, so locker 0 holds Bolt and locker 1 holds Ace - squad[1] is the SECOND hero.
Check
nums is [10, 20, 30, 40]. This exact question was on the diagnostic.
Check your understanding
What does print(nums[1:3]) show?
Answer: C
Why: Start at index 1 (the 20), stop BEFORE index 3 - so only indexes 1 and 2 come along. Count check: 3 - 1 = 2 items.
Check
Another one straight off the diagnostic. What kind of values are these?
Check your understanding
What does print([1, 2] + [3]) show?
Answer: B
Why: + between two lists glues them end-to-end into one new list: [1, 2, 3]. It never does arithmetic on the items inside.
Check
Last of the three diagnostic questions. Stamp or multiply?
Check your understanding
What does print([0] * 3) show?
Answer: C
Why: * repeats the whole list: three stamps of [0] make [0, 0, 0]. The length multiplies; the values inside never change.
Elimination
Eliminate the wrong options
team has 8 items. How many items are in team[2:5]?
3 of these 4 are wrong. Strike them one at a time, and say what rules each one out before you strike the next. The survivor is the answer.
Survives elimination: B
Why: A slice holds end minus start items: 5 - 2 = 3 (indexes 2, 3, and 4 - the 5 is excluded).
Check
No list needed - just the counting rule.
Check your understanding
team has 8 items. How many items are in team[2:5]?
Answer: B
Why: A slice holds end minus start items: 5 - 2 = 3 (indexes 2, 3, and 4 - the 5 is excluded).
Concept
Now you build, on your own. Mission: a roster program for your dream team of robots or heroes.
| # | requirement | tool you'll use |
|---|---|---|
| 1 | a squad list with SIX names | [ ] and commas |
| 2 | print the starting lineup - first three - with ONE slice | [:3] |
| 3 | merge a second squad onto the team | + |
| 4 | stretch: captain, bench, and a chant | [0], [3:], * |
Rules of the build: type everything yourself, run after every line, and when something surprises you - read the error, do not erase it. Hints are one beat away if you get stuck.
Analogy
Discussion prompt
Explain PROJECT: Dream Team Roster by analogy to something with no Python in it at all — a queue, a recipe, a map, a bank balance, whatever fits. Then say where your analogy breaks.
Hint: An analogy that never breaks is not an analogy, it is the same idea wearing a hat. Find the seam — that is the part that is actually new.
Answer:
Rules of the build: type everything yourself, run after every line, and when something surprises you - read the error, do not erase it. Hints are one beat away if you get stuck.
Worked example
Your turn (about 5 minutes): make a list called squad with six names you like, then prove it works by printing the list and its length. Don't peek ahead until it runs.
Hint: six strings in quotes, commas between, square brackets around. len(squad) should print 6.
squad = ["Bolt", "Ace", "Nova", "Rex", "Zap", "Pixel"]
print(squad)
print(len(squad))| you should see | |
|---|---|
| the six names in brackets | ['Bolt', 'Ace', 'Nova', 'Rex', 'Zap', 'Pixel'] |
| the count | 6 |
Worked example
Your turn: print the starting lineup - the first three heroes - using exactly one slice. Before you run it, say out loud how many names will print.
Hint: "the first three" is a slice with a blank start. Where does it stop - and is that index included?
print("Starters:", squad[0:3])| expression | result |
|---|---|
| squad[0:3] | ['Bolt', 'Ace', 'Nova'] |
| squad[:3] | same thing - blank start means 0 |
| items printed | 3 - 0 = 3 |
Worked example
Your turn: make a second list squad2 with two new recruits, merge it onto your squad with + into a variable called team, and print the full team and its new length.
Hint: + makes a NEW list - catch it in a variable or it vanishes. Predict the new length before you print it.
squad2 = ["Turbo", "Glitch"]
team = squad + squad2
print("Full team:", team)
print(len(team))| check | expected |
|---|---|
| recruits at the END of the printout | ..., 'Pixel', 'Turbo', 'Glitch'] |
| len(team) | 8 - lengths add, items never do |
Trade off
Comparison matrix
From Build it 3: merge the recruits - your turn: every row here is a choice with a cost. Fill the expected column, then say which row you would actually pick and what you give up for it.
| check | expected |
|---|---|
| recruits at the END of the printout | ..., 'Pixel', 'Turbo', 'Glitch'] |
| len(team) | 8 - lengths add, items never do |
Worked example
Stretch goals, your turn: print the captain (the very first team member), the bench (everyone from index 3 on), and a chant that says Go! three times - using *, not three print calls.
Hint: captain is a single index. Bench is a slice with a blank end. The chant is a 1-item list stamped 3 times.
print("Captain:", team[0])
print("Bench:", team[3:])
print(["Go!"] * 3)| line | what prints |
|---|---|
| team[0] | Bolt |
| team[3:] | ['Rex', 'Zap', 'Pixel', 'Turbo', 'Glitch'] |
| ["Go!"] * 3 | ['Go!', 'Go!', 'Go!'] |
Comparison
Comparison matrix
From Build it 4 (stretch): captain, bench, chant: refill the what prints column from what you know. The rest of the table is as it appeared.
| line | what prints |
|---|---|
| team[0] | Bolt |
| team[3:] | ['Rex', 'Zap', 'Pixel', 'Turbo', 'Glitch'] |
| ["Go!"] * 3 | ['Go!', 'Go!', 'Go!'] |
Estimation
Predict first
If yours prints your own six heroes in the same shape - you built it. Different names, same superpowers.
Commit before you compute: what does The whole roster program come out to? A rough magnitude and the right form is enough — the point is to have something concrete to be wrong about.
Correct: Read the program top to bottom
Why: A prediction you can defend turns the computation into a check rather than a leap of faith — and an answer that contradicts it is caught on the spot. Draft the squad, slice the starters, merge the recruits, then index, slice, and stamp - every tool from the hour in nine lines.
Worked example
squad = ["Bolt", "Ace", "Nova", "Rex", "Zap", "Pixel"]
print("Starters:", squad[0:3])
squad2 = ["Turbo", "Glitch"]
team = squad + squad2
print("Full team:", team)
print("Captain:", team[0])
print("Bench:", team[3:])
print(["Go!"] * 3)Read the program top to bottom
Why: Draft the squad, slice the starters, merge the recruits, then index, slice, and stamp - every tool from the hour in nine lines.
| line | output |
|---|---|
| Starters: | ['Bolt', 'Ace', 'Nova'] |
| Full team: | ['Bolt', 'Ace', 'Nova', 'Rex', 'Zap', 'Pixel', 'Turbo', 'Glitch'] |
| Captain: | Bolt |
| Bench: | ['Rex', 'Zap', 'Pixel', 'Turbo', 'Glitch'] |
| chant | ['Go!', 'Go!', 'Go!'] |
If yours prints your own six heroes in the same shape - you built it. Different names, same superpowers.
Reverse engineer
Discussion prompt
Work backwards. The example finished here:
Read the program top to bottom
What was it asked to do, and what must it have been given? Reconstruct the problem from its answer.
Hint: Every quantity in the result had to enter somewhere. Account for each one.
Answer:
If yours prints your own six heroes in the same shape - you built it. Different names, same superpowers.
Concept
Last 5 minutes: run your roster and explain it line by line - what [:3] grabs and why the end index stays out, why + made the team longer but never did math, and what * 3 stamped out.
If you can explain those three, you just aced the exact three questions the diagnostic said were impossible.
Counterexample
Discussion prompt
Last 5 minutes: run your roster and explain it line by line - what [:3] grabs and why the end index stays out, why + made the team longer but never did math, and what * 3 stamped out.
That is stated as though it always holds. Do one of two things: produce a case where it fails, or say precisely what rules such a case out. "It just does" is not on the menu.
Hint: Hunt at the extremes first — zero, one, negative, empty, equal. If every extreme survives, the reason they survive is the proof.
Answer:
If you can explain those three, you just aced the exact three questions the diagnostic said were impossible.
Connect it up
Draw it
One page, no notation unless you need it: draw how these connect — The list toolbox · Why lists matter at camp · What a list is · Lockers numbered from 0 · Indexing: grab one item. Put an arrow wherever one of them is what makes another possible, and label the arrow with why.
Recap
You can now grab any item with its index (starting at 0), slice exactly the chunk you want (end excluded - count is end minus start), join lists with +, repeat them with *, rewrite a locker, and grow a team with append. And you built a whole roster program with your own hands.
| the three diagnostic traps | the truth |
|---|---|
| [1, 2] + [3] | [1, 2, 3] - glue, not math |
| nums[1:3] | items 1 and 2 only - end excluded |
| [0] * 3 | [0, 0, 0] - a stamp, not multiplication |
Want this taught 1-on-1? Alexander tutors Python — $55/session, free consultation.