GCSE · Computer Science · OCR · Spec J277
2D arrays
"Row F, seat 12" finds one cinema seat. A 2D list works the same way, except both numbers start at 0. Swap them and you're in the wrong seat.
Computer Science · 2D lists
A table inside one variable
Three players, three rounds. Each row of scores is one player's scores, and each column is one round. Step through and watch what each line reaches.
Before you press Next twice: which number do you think scores[1][2] picks out?
1 scores = [[7, 5, 9],2 [4, 8, 6],3 [3, 10, 2]]4 print(scores[1])5 print(scores[1][2])6 scores[2][0] = 117 scores.append([6, 9, 4])8 print(scores[3])
Variables
Output
Step 1: One variable, three lists inside it. That's a table: 3 rows, 3 columns. The top row is row 0 and the left column is column 0. Both start from 0.
Each chip is one row of the table. The output box shows what each print line gives.
Computer Science · Reading the syntax
What does each line do?
Sort each line by what it does to temps.
Still to sort
Gets a whole row (0)
One index in square brackets.
Where the line is: Only one set of square brackets after temps, so you get the full row, not one value.
Gets a single item (0)
Row index, then column index, and the value is only read.
Where the line is: Two indexes but nothing assigned to that location: the table doesn't change.
Replaces an item (0)
Both indexes on the left of =.
Where the line is: The location named on the left of = gets a new value. Two indexes on the right side are only being read.
Adds a new row (0)
append() with the new row given as a list.
Where the line is: The table gains a row at the end. Nothing already in it changes.
temps is a 2D list with 3 rows and 4 columns. Count the indexes, then check which side of the = they're on.
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
One variable, a whole table of values. Every value has a two-number address: row first, then column, and both start at 0.
What you need to know
- A 2D array or list stores several arrays or lists in one variable.
- Two-dimensional just means it has both rows and columns of values, so picture a table.
- Every row and every column has an index number, and both start from 0.
- One index in square brackets, like scores[1], gives you a whole row.
Have a got = [[2, 4], [6, 8], [1, 3]]. What does t[2] give you?
[1, 3]
One index picks a whole row, and counting starts at 0, so index 2 is the third row. [6, 8] is what you get by counting from 1.
- Two indexes give you a single item: row index first, then column index, as in scores[1][2].
Have a goSame t. Your friend bets their last biscuit that t[1][0] is 4, "because you go across 1, then down 0, like on a graph". Is the biscuit safe?
No: t[1][0] is 6. Enjoy the biscuit.
The row index comes first, so row 1 is [6, 8] and column 0 of it is 6. Reading it like x, y coordinates gives 4, which is really t[0][1].
- To replace an item, point at it with both indexes and assign the new value: scores[2][0] = 11.
- append() adds a new row to the end of a 2D list, and the row goes in as a list.
- That's a list job: a fixed-size array can't gain items, so it can't gain a row.
- Totalling a row uses the 1D loop with one tweak: add the row index, so each value is scores[row][i].
Have a goYou want to total row 0 of t. Inside the loop, which goes in the brackets: t[0][i] or t[i][0]?
t[0][i]
The row index stays fixed at 0 while the column index i moves along the row. t[i][0] fixes the column and changes the row, so it isn't adding row 0's values.
- Start the total at 0, add each value in the row, then divide by how many values there are.
The big picture
A two-dimensional (2D) array or list stores several arrays or lists in one variable: picture a table of rows and columns, both indexed from 0. One index, scores[1], gives a whole row; a row index then a column index, scores[1][2], gives one item. Assign to both indexes to replace an item. append() adds a new row, given as a list, to the end of a 2D list. To total or average one row, use the 1D loop with one adjustment: each value is scores[row][i].
Key points
Worked example
Problem
grid = [[2, 4, 6], [1, 3, 5]]. A program then runs grid[0][2] = grid[1][0] + 7, then grid.append([9, 8, 7]), then print(grid[2][1]) and print(grid[0]). What gets printed, and what does grid hold at the end?
⚠ Watch out
Putting the column index first, as if it were x, y coordinates. In scores[r][c] the first index is the row. Swap them and you read, or overwrite, a different value, often with no error to warn you.
Memory hook
Cinema seats: pick the row, then the seat. Row first, column second, and the front row is row 0.
Check yourself
Cover the page. For m = [[5, 1, 7], [2, 9, 4]], write the expression for the 9, a line changing the 7 to 0, and a line adding the row [3, 3, 3].
Flashcards
(12)What is a two-dimensional (2D) array or list?
What does "two-dimensional" describe?
In a 2D list, what number do the row and column indexes start from?
In scores[a][b], which index is the row and which is the column?
What part of the table does scores[2] give you?
How do you get a single item from a 2D list?
How do you replace one item in a 2D list?
How do you add a new row to the end of a 2D list?
Why does appending a row apply to a 2D list rather than a fixed-size array?
A 2D list has 5 rows. What is the index of the last row?
Looping through one row of a 2D list: what's the one adjustment from the 1D technique?
What's the method for the total and average of one row?
Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.
Learning with Lightbulb is opening soon
You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.
Keep me postedMore OCR GCSE Computer Science topics
- 1D arrays
- Basic string manipulation (concatenation, slicing)
- Boolean operators AND, OR, NOT
- Casting
- Constants
- Data type: Boolean
- Data type: Character and string
- Data type: Integer
- Data type: Real
- File handling: open, read, write, close
- Inputs, outputs, assignments
- Iteration (count- and condition-controlled loops)
How this lesson was checked. This OCR GCSE Computer Science (specification J277)lesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 3 November 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.