Editor

Fix the Bug: Nested List Trap

Intermediate · Fix the bug · from Working with Nested Lists, Dicts, and Complex Data Structures

From the lesson: Working with Nested Lists, Dicts, and Complex Data Structures

Think about a school. A school has classrooms. Each classroom has students. Each student has a name, an age, and a list of grades. That's data inside data inside data - nested data.

Read the lesson

This code tries to create a 3x3 grid and set only the center cell to "X". But something is wrong - run it and see! Fix the bug so only the center cell is "X" and all other cells remain ".".

Print each row on a separate line.

row = ['.'] * 3
grid = [row] * 3
grid[1][1] = 'X'
for r in grid:
print(r)

More nested data exercises

All Python exercises · 50 practice problems · Data Structures quiz