← Python

Sets – Basics

A set is an unordered collection of unique values defined with curly braces or set()

What it does: g[0] is [1,2], then [1] gives the second item: 2. A nested for loop visits every element in every inner list. Any list item can itself be a list — nesting creates multi-dimensional structures. grid[0] gets the first inner list — a second index is needed to get a number. grid[1] is [3,4], then [0] picks the first item — which is 3. len() counts the top-level items — there are 2 inner lists, not 4 numbers. Rows and columns map naturally to a list of lists. Lists are mutable — you can assign to any index including nested ones.

Common mistakes: Use two separate brackets grid[0][1], not a comma grid[0, 1]. grid has indices 0 and 1. Index 2 is out of range.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a journey and assign it to your class.

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
What is a nested list?
A list inside another listA sorted list
Matches
❌ g = [[1,2],[3,4]] print(g[2][0])
Error: Row index 2 out of range
Applying
Meanings
Term
Nested list
Meaning
A list that contains other lists as elements.
Practice
grid = [[1, 2], [3, 4]]
Testing
Gaps
print(grid[][1])
Check Answer
Spots
1grid = [[1, 2], [3, 4]]
2print(grid[0, 1])

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Giant Squid' badge — Nested Navigator, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. What is a nested list?
A. A list inside another list ✓
B. A sorted list
Any list item can itself be a list — nesting creates multi-dimensional structures
2. grid = [[1,2],[3,4]]\ngrid[0] returns?
A. 1
B. [1, 2] ✓
grid[0] gets the first inner list — a second index is needed to get a number
3. grid = [[1,2],[3,4]]\ngrid[0][1] returns?
A. 2 ✓
B. 1
grid[0] is [1,2], then [1] picks index 1 of that inner list — which is 2
4. grid = [[1,2],[3,4]]\ngrid[1][0] returns?
A. 4
B. 3 ✓
grid[1] is [3,4], then [0] picks the first item — which is 3
5. How do you loop through all items in a nested list?
A. Two nested for loops ✓
B. One for loop
The outer loop gets each inner list; the inner loop gets each item within it

Match the Pairs

g = [[1,2],[3,4]] print(g[2][0]) Error: Row index 2 out of range
g = [[1,2],[3,4]] print(g[0,1]) Error: Use g[0][1] not g[0,1]
g = [[1,2],[3,4]] g[0][1] Valid: Returns 2
for row in g: for item in row: print(item) Ok: Nested loops to traverse
g = [[1,2],[3,4]] print(g[1][0]) Output: 3
g = [[1,2],[3,4]] print(len(g)) Output: 2

Key Term

Nested list
A list that contains other lists as elements.~~grid[row][col]

Fill in the Blanks

1. grid = [[1, 2], [3, 4]] print(grid[0][1])
2. grid = [[1, 2], [3, 4]] print(grid[1][1])
3. for row in grid: for item in row: print(item)
4. grid = [[1, 2], [3, 4]] print(len( grid))
5. grid = [[1, 2], [3, 4]] grid[0][0] = 99 print(grid)

Spot the Error

Question 1
A grid = [[1, 2], [3, 4]]
B print(grid[0, 1])
Line B — Use two separate brackets grid[0][1], not a comma grid[0, 1]
Question 2
A grid = [[1, 2], [3, 4]]
B print(grid[2][0])
Line B — grid has indices 0 and 1. Index 2 is out of range.
Question 3
A grid = [[1, 2], [3, 4]]
B for item in grid:
C print(item) # expects individual numbers
Line B — One loop gives inner lists [1,2] and [3,4]. Need nested loops for individual items.
Question 4
A grid = [1, 2], [3, 4]
B first_row = grid[0]
C print('First row:', first_row)
D print('Item:', grid[0][1])
Line A — Missing outer brackets: this creates a tuple of lists, not a list of lists
Question 5
A grid = [[1, 2], [3, 4]]
B print(grid[0][1][0])
Line B — grid[0][1] is 2 (an integer). Can't index into a number.
For Teachers

Create a free class, add this module to a journey, and track who's stuck.

Create a free teacher account →

No credit card. No setup fee. Make a class and invite students in under three minutes.

For Students

Practice this topic interactively, track progress, and unlock badges.

Start Learning Free →

Have a class code?