🗂️ Python data structures · session 1 of 12 · 60 minutes · free
Getting started with lists
Every app keeps collections: songs in a playlist, scores in a game, messages in a chat. In Python the go-to collection is the list. Today you build Beatbox's playlists: make them, read any song by its position, cut out parts, change them with methods and stack lists inside lists.

A complete lesson · 60 minutes
Teach it, see it, practise it, all on this page.
Open this page with your learner and work down it, or press Teach this lesson to go through it one step at a time on a big screen. Every section has something to do.
- Warm-up3 min
- Warm-up games5 min
- Lists: make them, index them9 min
- Slicing, looping and joining lists9 min
- List methods and nested lists9 min
- Beatbox playlist builder7 min
- Bookend words7 min
- Class marks report5 min
- Quiz5 min
- Set the after-class project1 min
By the end you can
- Explain what a data structure is and name Python's four built-in ones
- Make lists and read items with positive and negative indexes
- Slice a list, loop over it, join lists with + and extend(), repeat with *
- Change a list with append, insert, remove, pop, sort and reverse
- Read and change items in a nested list (a list of lists)
Before you start
- Variables, if and for loops
- Writing a function with def and return
- f-strings
Have ready
- This page (the code runs in the browser)
- Paper to draw boxes with index numbers
Grades 9 to 12 · ages 14 to 18 · after a first Python course
Warm-up · think first
Your phone keeps 2,000 songs. Would you rather store them in 2,000 separate variables (song1, song2, …) or in one thing? Why?
Show the answer
One thing: a list. One name holds them all in order, you can loop over them, sort them, count them and add more with one line. That's what data structures are for.
Teacher tip: Ask what else on their phone is 'a list of things'.
🎮 Warm-up games · 5 quick games
Play with Bolt the robot
Five minutes in the Beatbox studio. Vote, say why, then show the answer.
- Which one is not one of Python's four built-in data structures? (List · Tuple · Array · Dictionary)
Answer: Array is the odd one out. Python's four are list, tuple, dictionary and set (arrays come from extra modules). - The first item of a Python list is at position 1. (Always · Sometimes · Never)
Answer: Never — Never. Python counts from 0, so the first item is at index 0. - A queue of 6 people. Who is at position -1?
Answer: The last person. Negative indexes count from the end: -1 is the last, -2 the one before. - Would you rather sort your playlist by hand or with one line of code? (Drag 2,000 songs by hand · playlist.sort())
Answer: One line: playlist.sort(). Today you'll write it. - Name three lists inside apps you use.
Answer: A chat's messages, a game's leaderboard, a shop's cart, a feed's posts. Every one is a list in code.
Three levels, like a real engineer
Use it. Tweak it. Build it.
First use what the lesson shows exactly as it is, then change one key thing and see what happens, then make your own.
- 🔒
Level 1 · Use it
Watch the list grow
Run the example where a list of colors uses the append method. Watch carefully how the list changes and gets longer after each new color is added to it.
- 🔧
Level 2 · Tweak it
Adjust the slice
In the slicing code numbers[0:3] on [10, 20, 30, 40, 50], change the end index from 3 to 2. Predict how many items you get, then run it and check.
- 🛠️
Level 3 · Build it
Design your own list
Create a list named 'MyToys' that holds three different items. Use a loop to print each toy's name to the screen.
🗺️ Play the Lesson QuestThree worlds, one for each level, with short stages that bring back what you miss.
Part 1 of 3 · learn, see, practise
Lists: make them, index them
Beatbox dev log, day 1. Separate variables for every song won't scale. One list holds them all, in order, and each song has a position number called an index.
A data structure stores a collection and lets you work on it. Python has four built in: list, tuple, dictionary and set. Today: the list.
A list is written in square brackets with commas: songs = ["Glow", "Rush", "Echo"]. Items can be any type, even mixed: [7, "hi", 2.5, True].
Indexes start at 0: songs[0] is the first item. Negative indexes count from the end: songs[-1] is the last. len(songs) is how many items there are. An index past the end gives IndexError.
🧑🏫 Teacher: type this live with the class
Build the first playlist
songs = ["Glow", "Rush", "Echo", "Drift"]Square brackets, commas between items. Ask: how many songs?
print(len(songs))len counts the items: 4.
print(songs[0])Index 0 is the first song. Ask before running.
print(songs[-1])-1 is the last one: Drift.
songs[1] = "Rise"Lists can be changed: replace the item at index 1.
print(songs)Run it: the whole list with Rise in place of Rush.
▶ Output
(nothing is printed)
📦 Memory boxes
▶ Output
Players: 5 First: 72 Last: 80 Second from last: 61 [72, 88, 95, 66, 80] hi 4
📦 Memory boxes
[72, 88, 95, 66, 80]listmixed[7, 'hi', 2.5, True]listTry print(scores[5]). Read the IndexError: why is 5 too far for a list of 5?
Puzzle break: count from zero
Read it the way Python does, line by line, before anyone runs it.
- Puzzle 1: say what happens before you run it
- Puzzle 2: say what happens before you run it
- Puzzle 3: fill the gap
Practise it
Start with the warm-up and go as far as you can. The stretch questions are meant to be hard.
1.1 Make a list called colours with "red", "green" and "blue", then print how many items it has.
▶ Output
(nothing is printed)
📦 Memory boxes
🧑🏫 Model answer (for the teacher)
Teacher eyes only: hide the answers before you share your screen.
The answer green = the 2 lines the student writes
colours = ["red", "green", "blue"]print(len(colours))
What it prints
3
What ✓ Check looks for
- it prints exactly:
3
- In the code: Use len(colours).
1.2 Print the first and the last song on two lines, using indexes.
▶ Output
(nothing is printed)
📦 Memory boxes
['Glow', 'Rush', 'Echo', 'Drift']list🧑🏫 Model answer (for the teacher)
Teacher eyes only: hide the answers before you share your screen.
The answer green = the 2 lines the student writes
songs = ["Glow", "Rush", "Echo", "Drift"]print(songs[0])print(songs[-1])
What it prints
Glow Drift
What ✓ Check looks for
- it prints exactly:
Glow Drift
- In the code: The last item is songs[-1].
1.3 Replace the third song with "Spark" and print the list.
▶ Output
(nothing is printed)
📦 Memory boxes
['Glow', 'Rush', 'Echo', 'Drift']list🧑🏫 Model answer (for the teacher)
Teacher eyes only: hide the answers before you share your screen.
The answer green = the 2 lines the student writes
songs = ["Glow", "Rush", "Echo", "Drift"]songs[2] = "Spark"print(songs)
What it prints
['Glow', 'Rush', 'Spark', 'Drift']
What ✓ Check looks for
- it prints exactly:
['Glow', 'Rush', 'Spark', 'Drift']
- In the code: The third song is at index 2.
1.4 Print the middle item of any list with an odd length, using len() (no fixed number).
▶ Output
(nothing is printed)
📦 Memory boxes
[4, 8, 15, 16, 23]list🧑🏫 Model answer (for the teacher)
Teacher eyes only: hide the answers before you share your screen.
The answer green = the 1 line the student writes
nums = [4, 8, 15, 16, 23]print(nums[len(nums) // 2])
What it prints
15
What ✓ Check looks for
- it prints exactly:
15
- With
nums = [1, 2, 3, 4, 5, 6, 7], it prints exactly:4
1.5 Swap the first and the last items of the list in one line, then print it.
▶ Output
(nothing is printed)
📦 Memory boxes
['Ana', 'Ben', 'Cy', 'Dee']list🧑🏫 Model answer (for the teacher)
Teacher eyes only: hide the answers before you share your screen.
The answer green = the 2 lines the student writes
queue = ["Ana", "Ben", "Cy", "Dee"]queue[0], queue[-1] = queue[-1], queue[0]print(queue)
What it prints
['Dee', 'Ben', 'Cy', 'Ana']
What ✓ Check looks for
- it prints exactly:
['Dee', 'Ben', 'Cy', 'Ana']
- With
queue = ["x", "y"], it prints exactly:['y', 'x']
1.6 Print the second-to-last item, then the item that is as far from the start as -2 is from the end (that is, index 1).
▶ Output
(nothing is printed)
📦 Memory boxes
['easy', 'normal', 'hard', 'expert', 'insane']list🧑🏫 Model answer (for the teacher)
Teacher eyes only: hide the answers before you share your screen.
The answer green = the 2 lines the student writes
levels = ["easy", "normal", "hard", "expert", "insane"]print(levels[-2])print(levels[1])
What it prints
expert normal
What ✓ Check looks for
- it prints exactly:
expert normal
- In the code: Second-to-last is levels[-2].
Part 2 of 3 · learn, see, practise
Slicing, looping and joining lists
Users want 'the top 3', 'everything but the intro' and 'play it all twice'. Slices cut out parts of a list, loops walk through it, and + and * build new lists.
A slice list[start:stop] gives a new list from start up to, but not including, stop: nums[1:4] is items 1, 2 and 3. Leave out start or stop to go from the beginning or to the end: nums[:3], nums[2:].
A third number is the step: nums[::2] takes every second item, and nums[::-1] is the list reversed.
for item in nums: visits every item in order. + joins two lists into a new one; a.extend(b) adds b's items onto the end of a. [0] * 4 makes [0, 0, 0, 0].
🧑🏫 Teacher: type this live with the class
Cut, loop and join
chart = ["Glow", "Rush", "Echo", "Drift", "Spark"]A chart of five songs.
print(chart[:3])The top 3: indexes 0, 1, 2. Ask why not 3.
print(chart[2:])From index 2 to the end.
print(chart[::-1])Step -1: the whole list backwards.
for song in chart:Visit every song.
print("Now playing:", song)Four spaces in, like an if.
print(chart + ["Bonus"])+ makes a new, longer list.
print(["la"] * 3)* repeats the items.
▶ Output
(nothing is printed)
📦 Memory boxes
▶ Output
Weekdays: [12, 7, 15, 9, 20] Weekend: [18, 5] Every other day: [12, 15, 20, 5] Backwards: [5, 18, 20, 9, 15, 7, 12] Total plays: 86 ['Glow', 'Rush', 'Echo'] ['*', '*', '*']
📦 Memory boxes
[12, 7, 15, 9, 20, 18, 5]listtotal86intplays5intmorning['Glow', 'Rush', 'Echo']listChange the slices: what is week[2:2]? What about week[-3:]?
Puzzle break: slices
Read it the way Python does, line by line, before anyone runs it.
- Puzzle 1: say what happens before you run it
- Puzzle 2: fill the gap
- Puzzle 3: put the lines in order
Practise it
Start with the warm-up and go as far as you can. The stretch questions are meant to be hard.
2.1 Print the first three items using a slice.
▶ Output
(nothing is printed)
📦 Memory boxes
[10, 20, 30, 40, 50]list🧑🏫 Model answer (for the teacher)
Teacher eyes only: hide the answers before you share your screen.
The answer green = the 1 line the student writes
nums = [10, 20, 30, 40, 50]print(nums[:3])
What it prints
[10, 20, 30]
What ✓ Check looks for
- it prints exactly:
[10, 20, 30]
- In the code: Use nums[:3].
2.2 Print every song on its own line, with a for loop.
▶ Output
(nothing is printed)
📦 Memory boxes
['Glow', 'Rush', 'Echo']list🧑🏫 Model answer (for the teacher)
Teacher eyes only: hide the answers before you share your screen.
The answer green = the 2 lines the student writes
playlist = ["Glow", "Rush", "Echo"]for song in playlist: print(song)
What it prints
Glow Rush Echo
What ✓ Check looks for
- it prints exactly:
Glow Rush Echo
- In the code: Use for song in playlist:
2.3 Print the list reversed using a slice, then every second item starting from the first.
▶ Output
(nothing is printed)
📦 Memory boxes
['a', 'b', 'c', 'd', 'e', 'f']list🧑🏫 Model answer (for the teacher)
Teacher eyes only: hide the answers before you share your screen.
The answer green = the 2 lines the student writes
letters = ["a", "b", "c", "d", "e", "f"]print(letters[::-1])print(letters[::2])
What it prints
['f', 'e', 'd', 'c', 'b', 'a'] ['a', 'c', 'e']
What ✓ Check looks for
- it prints exactly:
['f', 'e', 'd', 'c', 'b', 'a'] ['a', 'c', 'e']
- In the code: Reverse with letters[::-1].
2.4 Join the two lists into one called all_songs with +, add "Encore" to the end with extend, then print it.
▶ Output
(nothing is printed)
📦 Memory boxes
['Glow', 'Rush']listside_b['Echo']list🧑🏫 Model answer (for the teacher)
Teacher eyes only: hide the answers before you share your screen.
The answer green = the 3 lines the student writes
side_a = ["Glow", "Rush"]side_b = ["Echo"]all_songs = side_a + side_ball_songs.extend(["Encore"])print(all_songs)
What it prints
['Glow', 'Rush', 'Echo', 'Encore']
What ✓ Check looks for
- it prints exactly:
['Glow', 'Rush', 'Echo', 'Encore']
- In the code: Join with side_a + side_b.
- In the code: Add with all_songs.extend([...]).
2.5 Add up the numbers with a loop (not sum) and print the total and the average to 2 decimal places, like: Total: 46 Average: 5.75
▶ Output
(nothing is printed)
📦 Memory boxes
[4, 5, 1, 2, 9, 7, 10, 8]list🧑🏫 Model answer (for the teacher)
Teacher eyes only: hide the answers before you share your screen.
The answer green = the 4 lines the student writes
L = [4, 5, 1, 2, 9, 7, 10, 8]total = 0for n in L: total += nprint(f"Total: {total} Average: {total / len(L):.2f}")
What it prints
Total: 46 Average: 5.75
What ✓ Check looks for
- it prints exactly:
Total: 46 Average: 5.75
- With
L = [1, 2], it prints exactly:Total: 3 Average: 1.50
- In the code: Use a for loop.
2.6 Build a 3 × 4 grid of zeros: a list of 3 rows, each a list of 4 zeros, without typing them out. Print it.
▶ Output
(nothing is printed)
📦 Memory boxes
🧑🏫 Model answer (for the teacher)
Teacher eyes only: hide the answers before you share your screen.
The answer green = the 4 lines the student writes
grid = []for r in range(3): grid.append([0] * 4)print(grid)
What it prints
[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
What ✓ Check looks for
- it prints exactly:
[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
- In the code: Use * to repeat.
Part 3 of 3 · learn, see, practise
List methods and nested lists
Users add, remove and reorder songs all day. List methods do the work: one dot and one word. And an album is a list of songs, so a library is a list of lists.
append(x) adds to the end; insert(i, x) puts x at index i; remove(x) deletes the first x; pop() removes and returns the last item (pop(i) the item at i).
sort() puts the list in order (sort(reverse=True) backwards); reverse() flips it; count(x) counts; index(x) finds the first position. These change the list itself and most return None, so don't write songs = songs.sort().
A nested list holds lists: grid[1] is the second row, and grid[1][2] is the item at index 2 in that row. A for loop inside a for loop visits every item.
🧑🏫 Teacher: type this live with the class
Edit the playlist, then the album rack
q = ["Rush", "Glow"]A small queue.
q.append("Echo")To the end.
q.insert(0, "Intro")To the front: index 0.
q.remove("Glow")Removes the first Glow.
last = q.pop()Takes the last song out and gives it back.
print(q, last)Run: ['Intro', 'Rush'] Echo.
rack = [["Glow", "Rush"], ["Echo", "Drift", "Spark"]]Two albums: a list of lists.
print(rack[1][2])Album 1, song 2: Spark.
print(len(rack), len(rack[1]))2 albums; the second has 3 songs.
▶ Output
(nothing is printed)
📦 Memory boxes
▶ Output
Sorted: [55, 64, 78, 91, 91] Lowest: 55 Highest: 91 How many 91s: 2 First 78 at: 2 [64, 91] best: 91 [78, 91, 55] best: 91 [88] best: 88 [[64, 91], [78, 91, 55], [88, 70]]
📦 Memory boxes
[55, 64, 78, 91, 91]listclass_marks[[64, 91], [78, 91, 55], [88, 70]]listrow[88, 70]listTry marks.sort(reverse=True). Then print(marks.sort()): why does it show None?
Puzzle break: methods and grids
Read it the way Python does, line by line, before anyone runs it.
- Puzzle 1: say what happens before you run it
- Puzzle 2: find the bug
- Puzzle 3: fill the gap
Practise it
Start with the warm-up and go as far as you can. The stretch questions are meant to be hard.
3.1 Add "Encore" to the end of the playlist and print it.
▶ Output
(nothing is printed)
📦 Memory boxes
['Glow', 'Rush']list🧑🏫 Model answer (for the teacher)
Teacher eyes only: hide the answers before you share your screen.
The answer green = the 2 lines the student writes
playlist = ["Glow", "Rush"]playlist.append("Encore")print(playlist)
What it prints
['Glow', 'Rush', 'Encore']
What ✓ Check looks for
- it prints exactly:
['Glow', 'Rush', 'Encore']
- In the code: Use playlist.append("Encore").
3.2 Sort the scores from lowest to highest and print them.
▶ Output
(nothing is printed)
📦 Memory boxes
[72, 88, 61, 95]list🧑🏫 Model answer (for the teacher)
Teacher eyes only: hide the answers before you share your screen.
The answer green = the 2 lines the student writes
scores = [72, 88, 61, 95]scores.sort()print(scores)
What it prints
[61, 72, 88, 95]
What ✓ Check looks for
- it prints exactly:
[61, 72, 88, 95]
- In the code: Use scores.sort().
3.3 Put "Intro" at the front, remove "Rush", then pop the last song and print the list and the popped song on one line.
▶ Output
(nothing is printed)
📦 Memory boxes
['Rush', 'Glow', 'Echo']list🧑🏫 Model answer (for the teacher)
Teacher eyes only: hide the answers before you share your screen.
The answer green = the 4 lines the student writes
q = ["Rush", "Glow", "Echo"]q.insert(0, "Intro")q.remove("Rush")last = q.pop()print(q, last)
What it prints
['Intro', 'Glow'] Echo
What ✓ Check looks for
- it prints exactly:
['Intro', 'Glow'] Echo
- In the code: Insert at index 0.
- In the code: Use remove.
- In the code: Use pop.
3.4 Print the song at row 1, position 0 of the rack, then how many songs the last album has.
▶ Output
(nothing is printed)
📦 Memory boxes
[['Glow', 'Rush'], ['Echo', 'Drift', 'Spark'], ['Nova']]list🧑🏫 Model answer (for the teacher)
Teacher eyes only: hide the answers before you share your screen.
The answer green = the 2 lines the student writes
rack = [["Glow", "Rush"], ["Echo", "Drift", "Spark"], ["Nova"]]print(rack[1][0])print(len(rack[-1]))
What it prints
Echo 1
What ✓ Check looks for
- it prints exactly:
Echo 1
- In the code: Row 1, position 0 is rack[1][0].
3.5 Without using sort(), print the smallest and largest numbers by looping once and keeping track of both, like: Smallest: 1 Largest: 10
▶ Output
(nothing is printed)
📦 Memory boxes
[4, 5, 1, 2, 9, 7, 10, 8]list🧑🏫 Model answer (for the teacher)
Teacher eyes only: hide the answers before you share your screen.
The answer green = the 7 lines the student writes
L = [4, 5, 1, 2, 9, 7, 10, 8]small = big = L[0]for n in L: if n < small: small = n if n > big: big = nprint(f"Smallest: {small} Largest: {big}")
What it prints
Smallest: 1 Largest: 10
What ✓ Check looks for
- it prints exactly:
Smallest: 1 Largest: 10
- With
L = [3, -2, 8], it prints exactly:Smallest: -2 Largest: 8
- In the code: Loop over L once.
3.6 Add up every number in the nested list with two loops and print the total.
▶ Output
(nothing is printed)
📦 Memory boxes
[[3, 1, 4], [1, 5], [9, 2, 6]]list🧑🏫 Model answer (for the teacher)
Teacher eyes only: hide the answers before you share your screen.
The answer green = the 5 lines the student writes
grid = [[3, 1, 4], [1, 5], [9, 2, 6]]total = 0for row in grid: for n in row: total += nprint(total)
What it prints
31
What ✓ Check looks for
- it prints exactly:
31
- With
grid = [[1], [2, 3]], it prints exactly:6
- In the code: Use a loop inside a loop.
Watch out
Common mistakes
Counting from 1
The first item is list[0]; the last is list[-1] or list[len(list) - 1].
Expecting the stop in a slice
nums[1:4] stops before index 4: three items.
Writing x = x.sort()
sort() changes the list and returns None, so x becomes None. Just write x.sort(), or use sorted(x) for a new list.
Mixing up remove and pop
remove(x) deletes by value; pop(i) deletes by position and gives the item back.
Building a grid with [[0] * 4] * 3
That makes three references to the same row: change one and all change. Build rows in a loop.
Class activity 1 of 3
Beatbox playlist builder
Build a playlist step by step with list operations. When it works it prints:
[]
['Glow', 'Rush', 'Echo']
['Glow', 'Rush', 'Echo', 'Glow', 'Rush', 'Echo']
['Echo', 'Rush', 'Glow', 'Echo', 'Rush', 'Glow']
Songs: 6
- Make an empty list and print it.
- Make a list of three songs and print it.
- Repeat it twice with * into a new list.
- Reverse that list with a slice, print it, then print how many songs there are.
▶ Output
(nothing is printed)
📦 Memory boxes
Hint
songs * 2 makes a new list with every item twice, in order. [::-1] walks it backwards.
🧑🏫 Model answer (for the teacher)
Teacher eyes only: hide the answers before you share your screen.
The answer green = the 9 lines the student writes
# ===== Beatbox playlist builder =====empty = []print(empty)songs = ["Glow", "Rush", "Echo"]print(songs)twice = songs * 2print(twice)twice = twice[::-1]print(twice)print("Songs:", len(twice))
What it prints
[] ['Glow', 'Rush', 'Echo'] ['Glow', 'Rush', 'Echo', 'Glow', 'Rush', 'Echo'] ['Echo', 'Rush', 'Glow', 'Echo', 'Rush', 'Glow'] Songs: 6
What ✓ Check looks for
- it prints exactly:
[] ['Glow', 'Rush', 'Echo'] ['Glow', 'Rush', 'Echo', 'Glow', 'Rush', 'Echo'] ['Echo', 'Rush', 'Glow', 'Echo', 'Rush', 'Glow'] Songs: 6
- In the code: Step 3: repeat with * 2.
- In the code: Step 4: reverse with [::-1].
If they're stuck, say
songs * 2 makes a new list with every item twice, in order. [::-1] walks it backwards.
Class activity 2 of 3
Bookend words
A bookend word starts and ends with the same letter, like 'level' or 'that'. Write a function that finds them in a list, prints them, and returns how many there are. One-letter words don't count. When it works it prints:
['level', 'that', 'xyzx', 'aba']
Bookend words: 4
- Write def bookends(words): with a counter and an empty result list.
- Loop over the words; a word counts when len(word) > 1 and word[0] == word[-1].
- Add each match to the list and add 1 to the counter.
- Print the list and return the counter; call it and print the count.
▶ Output
(nothing is printed)
📦 Memory boxes
['level', 'beat', 'that', 'a', 'xyzx', 'song', 'aba']listHint
word[0] is the first letter and word[-1] the last. Check len(word) > 1 first, so 'a' is skipped.
🧑🏫 Model answer (for the teacher)
Teacher eyes only: hide the answers before you share your screen.
The answer green = the 11 lines the student writes
# ===== Bookend words =====def bookends(words): count = 0 found = [] for word in words: if len(word) > 1 and word[0] == word[-1]: count += 1 found.append(word) print(found) return count words = ["level", "beat", "that", "a", "xyzx", "song", "aba"]n = bookends(words)print("Bookend words:", n)
What it prints
['level', 'that', 'xyzx', 'aba'] Bookend words: 4
What ✓ Check looks for
- it prints exactly:
['level', 'that', 'xyzx', 'aba'] Bookend words: 4
- With
words = ["noon", "xx", "q", "pop", "tune"], it prints exactly:['noon', 'xx', 'pop'] Bookend words: 3
- In the code: Step 1: write the function.
- In the code: The last letter is word[-1].
If they're stuck, say
word[0] is the first letter and word[-1] the last. Check len(word) > 1 first, so 'a' is skipped.
Class activity 3 of 3
Class marks report
Turn a list of marks into a report. When it works it prints:
Marks: [64, 91, 78, 55, 88]
Total: 376
Average: 75.2
Lowest: 55
Highest: 91
Top three: [91, 88, 78]
- Print the marks.
- Add them with a loop; work out the average.
- Sort a copy, then use index 0 and -1 for lowest and highest.
- The top three are the sorted copy's last three, highest first.
▶ Output
(nothing is printed)
📦 Memory boxes
[64, 91, 78, 55, 88]listHint
sorted(marks) gives a new sorted list and leaves marks as it was. [::-1] then [:3] takes the top three.
🧑🏫 Model answer (for the teacher)
Teacher eyes only: hide the answers before you share your screen.
The answer green = the 10 lines the student writes
# ===== Class marks report =====marks = [64, 91, 78, 55, 88]print("Marks:", marks)total = 0for m in marks: total += mprint("Total:", total)print("Average:", round(total / len(marks), 1))ordered = sorted(marks)print("Lowest:", ordered[0])print("Highest:", ordered[-1])print("Top three:", ordered[::-1][:3])
What it prints
Marks: [64, 91, 78, 55, 88] Total: 376 Average: 75.2 Lowest: 55 Highest: 91 Top three: [91, 88, 78]
What ✓ Check looks for
- it prints exactly:
Marks: [64, 91, 78, 55, 88] Total: 376 Average: 75.2 Lowest: 55 Highest: 91 Top three: [91, 88, 78]
- With
marks = [40, 70, 100, 90], it prints exactly:Marks: [40, 70, 100, 90] Total: 300 Average: 75.0 Lowest: 40 Highest: 100 Top three: [100, 90, 70]
- In the code: Step 2: add with a loop.
If they're stuck, say
sorted(marks) gives a new sorted list and leaves marks as it was. [::-1] then [:3] takes the top three.
After class · project
My Beatbox playlist manager
Build a small playlist manager on a list: add songs, move a song to the top, remove a song, shuffle the order by a rule, and print a neat numbered playlist after every change.
What to make: A program with no errors that keeps a playlist in a list, with show() and to_top() functions, and prints the playlist after every change.
Stretch: Add swap(playlist, i, j) that swaps two songs by position, and a playlist of albums (a list of lists) that show() can also print.
How it is marked
| Look for | Done well when |
|---|---|
| Runs | No red error when you press Run |
| Methods | Uses append or extend, insert, remove and sort |
| Functions | show() and to_top() work for any playlist |
| Neat | A numbered playlist after every change |
Starter code to take home
Press Copy and paste it into the editor at home, or work on it right here.
▶ Output
(nothing is printed)
📦 Memory boxes
['Glow', 'Rush', 'Echo', 'Drift']list🔑 Show one possible solution (try it yourself first!)
▶ Output
1. Glow 2. Rush 3. Echo 4. Drift ------------ 1. Echo 2. Glow 3. Rush 4. Drift ------------ 1. Drift 2. Echo 3. Glow 4. Nova 5. Spark ------------
📦 Memory boxes
['Drift', 'Echo', 'Glow', 'Nova', 'Spark']listHomework
Practise at home
Each one checks itself. Or print the practice sheet.
1. Print how many items the list has and its last item, on two lines.
▶ Output
(nothing is printed)
📦 Memory boxes
['cat', 'dog', 'fish', 'hamster']list🧑🏫 Model answer (for the teacher)
Teacher eyes only: hide the answers before you share your screen.
The answer green = the 2 lines the student writes
pets = ["cat", "dog", "fish", "hamster"]print(len(pets))print(pets[-1])
What it prints
4 hamster
What ✓ Check looks for
- it prints exactly:
4 hamster
- In the code: Use len().
2. Print only the even numbers from the list, one per line, with a for loop and if.
▶ Output
(nothing is printed)
📦 Memory boxes
[3, 8, 11, 14, 20, 7]list🧑🏫 Model answer (for the teacher)
Teacher eyes only: hide the answers before you share your screen.
The answer green = the 3 lines the student writes
nums = [3, 8, 11, 14, 20, 7]for n in nums: if n % 2 == 0: print(n)
What it prints
8 14 20
What ✓ Check looks for
- it prints exactly:
8 14 20
- With
nums = [2, 5, 6], it prints exactly:2 6
3. Make a new list of the squares of nums with a loop and append, then print it.
▶ Output
(nothing is printed)
📦 Memory boxes
[1, 2, 3, 4]list🧑🏫 Model answer (for the teacher)
Teacher eyes only: hide the answers before you share your screen.
The answer green = the 4 lines the student writes
nums = [1, 2, 3, 4]squares = []for n in nums: squares.append(n * n)print(squares)
What it prints
[1, 4, 9, 16]
What ✓ Check looks for
- it prints exactly:
[1, 4, 9, 16]
- With
nums = [5], it prints exactly:[25]
- In the code: Use append.
4. Remove every 0 from the list (there may be several), then print it. Hint: while 0 in data:
▶ Output
(nothing is printed)
📦 Memory boxes
[0, 5, 0, 3, 0, 0, 8]list🧑🏫 Model answer (for the teacher)
Teacher eyes only: hide the answers before you share your screen.
The answer green = the 3 lines the student writes
data = [0, 5, 0, 3, 0, 0, 8]while 0 in data: data.remove(0)print(data)
What it prints
[5, 3, 8]
What ✓ Check looks for
- it prints exactly:
[5, 3, 8]
- With
data = [0, 0], it prints exactly:[]
5. Print the total of each row of the nested list, one per line, then the grand total.
▶ Output
(nothing is printed)
📦 Memory boxes
[[2, 4], [1, 1, 1], [10]]list🧑🏫 Model answer (for the teacher)
Teacher eyes only: hide the answers before you share your screen.
The answer green = the 8 lines the student writes
table = [[2, 4], [1, 1, 1], [10]]grand = 0for row in table: t = 0 for n in row: t += n print(t) grand += tprint(grand)
What it prints
6 3 10 19
What ✓ Check looks for
- it prints exactly:
6 3 10 19
- With
table = [[1], [2]], it prints exactly:1 2 3
🔥 Challenge round · finished early?
The hardest questions of the lesson, no notes
Cover the notes and try these from memory. They are meant to make you think hard: draw, try small cases, and check your answer.
- Stretch task 1: Swap the first and the last items of the list in one line, then print it.
- Stretch task 1: Print the second-to-last item, then the item that is as far from the start as -2 is from the end (that is, index 1).
- Stretch task 2: Add up the numbers with a loop (not sum) and print the total and the average to 2 decimal places, like: Total: 46 Average: 5.75
- Stretch task 2: Build a 3 × 4 grid of zeros: a list of 3 rows, each a list of 4 zeros, without typing them out. Print it.
- Stretch task 3: Without using sort(), print the smallest and largest numbers by looping once and keeping track of both, like: Smallest: 1 Largest: 10
- Stretch task 3: Add up every number in the nested list with two loops and print the total.
🧠 Think-hard question
Rotate a list left by k places with slices only (no loop): [1, 2, 3, 4, 5] rotated by 2 is [3, 4, 5, 1, 2]. Make it work when k is bigger than the length too.
Talk it through or use the drawing board. There is more than one way to get there.
Quiz · 8 questions
Final quiz: check what you learned
Pick an answer to see if it is right and why. Your best score is saved on this device.
🖨 Print what we learned
Make a worksheet from this lesson
Pick what to practise, then print it or choose Save as PDF in the print window to download it.
For parents and teachers
The 60-minute lesson plan
Use it as it is, or stretch any part over two sessions. Each row links to the part of the page you need.
| Time | Part | The teacher | The learner |
|---|---|---|---|
| 0–3 min | Warm-up | Ask the question and wait for a guess before any hint. | Guess, then explain. |
| 3–8 min | Warm-up games | Play three or four games. Ask for a reason each time. | Vote and say why. |
| 8–17 min | Lists: make them, index them | Type-along first: type each line, say the words, run it. Show the example, then do the puzzle break together before the practice. | Type along, crack the puzzles, then practise. |
| 17–26 min | Slicing, looping and joining lists | Type-along first: type each line, say the words, run it. Show the example, then do the puzzle break together before the practice. | Type along, crack the puzzles, then practise. |
| 26–35 min | List methods and nested lists | Type-along first: type each line, say the words, run it. Show the example, then do the puzzle break together before the practice. | Type along, crack the puzzles, then practise. |
| 35–42 min | Beatbox playlist builder | Show the boilerplate and read the numbered steps. Let them press Check often. | Follow the steps. |
| 42–49 min | Bookend words | Do step 1 together, then let them finish. | Finish the activity. |
| 49–54 min | Class marks report | If time is short, set it as homework. | Try the challenge. |
| 54–59 min | Quiz | Read each question aloud. Vote, then check. | Answer and read why. |
| 59–60 min | Set the after-class project | Open the project and agree a due date. | Copy the boilerplate. |
Questions to ask
- What does index -1 mean?
- Why does nums[1:4] give three items?
- What is the difference between remove and pop?
- Why should you not write x = x.sort()?
If it feels hard
Draw the list as a row of boxes with index numbers above (0, 1, 2…) and below (-1, -2… from the right). Point to boxes while reading each slice aloud.
If it feels easy
Rotate a list left by k places with slices only (no loop): [1, 2, 3, 4, 5] rotated by 2 is [3, 4, 5, 1, 2]. Make it work when k is bigger than the length too.
FAQ
Getting started with lists: questions
What is a list in Python?
An ordered, changeable collection written in square brackets, like [1, 2, 3]. Items can be of any type, and each has an index starting at 0.
What is the difference between append and extend?
append(x) adds one item (even if x is a list, it goes in as one item); extend(other) adds each item of another list.
How do I reverse a list?
nums[::-1] gives a reversed copy; nums.reverse() reverses the list itself.
Start a conversation
Want a teacher to take this class?
Tell us the learner's age and level. A teacher from our network teaches with these lessons; we confirm timing and price first.
- Tell us the learner’s age or grade and goals
- We’ll suggest a suitable class or learning path
- We’ll confirm format, timing and fees with a parent or guardian