Nested Lists and Iteration
Work with nested lists and iterate efficiently with for loops.
Nested Lists and Iteration is a free Python Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Python Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Introduction
Nested List Structure
matrix = [[1,2,3],[4,5,6],[7,8,9]]
print(matrix[1][2])Iterating Rows
matrix = [[1,2],[3,4]]
for row in matrix:
print(row)Nested for Loops
matrix = [[1,2],[3,4]]
for row in matrix:
for val in row:
print(val, end=' ')Flatten a Nested List
matrix = [[1,2],[3,4]]
flat = [x for row in matrix for x in row]
print(flat)Building a Grid
grid = [[0]*3 for _ in range(3)]
grid[0][0] = 1
print(grid)The Aliased Row Trap
bad = [[0]*3]*3
bad[0][0] = 9
print(bad) # all rows changed!zip() for Parallel Iteration
names = ['Alice', 'Bob']
scores = [90, 85]
for n, s in zip(names, scores):
print(n, s)enumerate() with Nested Lists
matrix = [[1,2],[3,4]]
for i, row in enumerate(matrix):
for j, val in enumerate(row):
print(f'[{i}][{j}]={val}')Sorting a List of Lists
data = [['Bob',85],['Alice',90],['Charlie',78]]
data.sort(key=lambda x: x[1])
print(data)Transposing a Matrix
matrix = [[1,2,3],[4,5,6]]
print(list(zip(*matrix)))Quick Check
Recap
Keep Going
Frequently asked questions
Is the “Nested Lists and Iteration” lesson free?
Yes — the full text of “Nested Lists and Iteration” is free to read here on the web, and the Python Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Python Academy course, upgrade to CoddyKit PRO.
What will I learn in “Nested Lists and Iteration”?
Work with nested lists and iterate efficiently with for loops. You practise Python Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Python Academy?
No prior experience is required. Python Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Nested Lists and Iteration” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Python Academy lesson?
Yes. Every Python Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Creating and Accessing Lists
- Modifying Lists
- Tuples and Immutability
- Nested Lists and Iteration