Python: tables with 2D lists
A game board, a seating plan and a class mark book are all tables: rows and columns. In Python you can store a table as a list of lists.
A list of lists
scores = [[5, 8, 6],
[9, 7, 10],
[4, 6, 7]]
This is called a two-dimensional (2D) list. Other languages call it a 2D array.
| Round 0 | Round 1 | Round 2 | |
|---|---|---|---|
| Player 0 | 5 | 8 | 6 |
| Player 1 | 9 | 7 | 10 |
| Player 2 | 4 | 6 | 7 |
Row first, then column
scores = [[5, 8, 6],
[9, 7, 10],
[4, 6, 7]]
print(scores[1][2])
print(scores[0][1])
Output:
10
8
len(scores) gives the number of rows (3); len(scores[0]) gives the number of columns in row 0 (3).
Nested loops
scores = [[5, 8, 6],
[9, 7, 10],
[4, 6, 7]]
for row in scores:
total = 0
for s in row:
total = total + s
print(total)
Output:
19
26
17
These are the total scores for each player. You can also change an item: board[2][2] = "X".
What does this print?
board = [["X", "O", "X"],
[" ", "X", "O"],
["O", " ", " "]]
board[2][2] = "X"
print(board[2])
- board[2] is the third row: O, space, space.
- board[2][2] = "X" changes the last item in that row.
- Printing the row shows the whole list.
Answer: ['O', ' ', 'X']
A 2D list is a list of lists that stores a table. Use name[row][column], with both indexes starting at 0. Nested loops visit every item.
- AND
- A Boolean operator that gives True (1) only when both inputs are True.
- List
- A data structure that stores many items under one name, in order, such as scores = [4, 7, 2].
- Output
- Information sent out from a computer, for example to a screen, speaker or printer.
Try two quick questions
See if it has sunk in. Answers are marked straight away.
2 more questions
Try each one, then tap to check.
grid is a 2D list with 5 rows, and each row has 6 items. How many items does it hold in total?
Show the answer
Answer: 30
5 × 6 = 30.
What is the FIRST number printed?
scores = [[5, 8, 6],
[9, 7, 10],
[4, 6, 7]]
for row in scores:
total = 0
for s in row:
total = total + s
print(total)Show the answer
Answer: 19
The first row totals 5 + 8 + 6 = 17.
Check you have got it
Answer 6 quick questions with instant marking. If you get one wrong, GCSE-ready shows you why and gives you another go. It is free, and you do not need an account.
Last updated 2 October 2026. Spotted a mistake? Tell us and we will fix it.