GCSE · Computer Science · Edexcel · Spec 1CP2
Two-dimensional arrays
Noughts and crosses, a seating plan, a spreadsheet: all tables, and Python can keep a whole one in one variable. The trick is asking for exactly the cell you want.
Computer Science · 2D lists
Which cell does it reach?
Step through a short program on a table of names and scores. Say the row and column before you press Next.
Before you press Next: which row, and which column, will this line reach?
1 # col 0 col 1 col 2 col 3 col 42 # row 0 "Ava" "Ben" "Cat" "Dev" "Eli"3 # row 1 12 30 25 18 414 scores = [["Ava", "Ben", "Cat", "Dev", "Eli"],5 [12, 30, 25, 18, 41]]6 print(scores[0])7 print(scores[1])8 print(scores[0][2])9 print(scores[1][0])10 scores[1][0] = 5011 print(scores)12 scores.append([10, 25, 40, 33, 49])13 print(scores)
Variables
Output
Step 1: Here is the whole table stored in ONE variable. Row 0 holds the names, row 1 holds the scores. The grey comment lines are just a picture of it, with the index numbers along the top and side.
Predict first, then step. Every value shown is written into the lesson; the page does not run the code.
Computer Science · Reading code
What does this line do?
Pick a line, then pick what it does.
Still to sort
Returns a whole row (0)
One index in brackets.
Where the line is: Only a row index is given, so a whole list comes back. Two indexes would return a single item.
Returns a single item (0)
Row index, then column index. No = sign.
Where the line is: Two indexes but no assignment: it reads one item and changes nothing.
Replaces an item (0)
Both indexes, then = and a new value.
Where the line is: It has the same two indexes as returning an item, but the = and new value overwrite that cell.
Adds a new row (0)
append() with a whole row inside.
Where the line is: No index picks a cell here: append() puts a whole new row at the end.
marks is a 2D list with 3 rows and 4 columns. Sort each line by what it does.
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
Store a whole table in one variable, then pick out any row or cell you like.
What you need to know
- An array is static: one name, many items, fixed size, all items one data type. Items can change, but not be added or deleted.
- A list is dynamic: its size can change, items can be added and deleted, and items can be different data types.
- A 2D array or list holds a list as each element, so it reads like a table of rows and columns.
- Row and column index numbers both start from zero, so the first row is row 0 and the first column is column 0.
Have a goYour classmate Sam says a table with 5 columns has a last column numbered 5. Is Sam right?
No. The last column is column 4.
Counting starts at zero, so five columns are numbered 0, 1, 2, 3, 4.
- In Python a 2D list is a list of lists: brackets round each row, another pair round all the rows, commas between rows.
- One index in brackets returns a whole row: scores[0] is the first row.
- Two indexes return one item, row first: scores[1][0] is the first item of the second row.
Have a goRow 0 of scores holds names. Write the expression that returns the fourth name.
scores[0][3]
Row index first (0, the names row), then column 3, because the first column is 0 so the fourth is 3.
- Replace one item with list_name[row][column] = new_value. Add a whole new row at the end with append().
Have a goscores has 2 rows. After scores.append([1, 2, 3, 4, 5]), how many rows is that, and what is the new row's index?
3 rows; the new row has index 2.
append() adds the new row at the end, and row indexes keep counting from zero: 0, 1, 2.
- To total or average one row, loop through it with the row index included, then divide the total by the number of values.
- Print a game board row by row with a loop through each row and, inside it, a loop through each column.
The big picture
A 2D list is a list of lists that you read like a table. The first index picks the row, the second picks the column, and both count from zero. With those two indexes you can return a row, return or replace an item, add a row with append(), total a row in a loop and print a game board.
Key points
Worked example
Problem
A 3 x 3 noughts-and-crosses board is stored as a 2D list, with "-" meaning an empty cell. Print it row by row as a grid.
⚠ Watch out
Writing the column index first (for example board[x][y] when y is the row), or counting rows and columns from 1. Either one quietly picks the wrong cell. Say it as row, then column, starting at 0.
Memory hook
Open the big box first (the row), then pick the item inside it (the column) - and the first box is always numbered 0.
Check yourself
seats is a 2D list with 3 rows and 4 columns. Write the expression for the last row, last column. Check: seats[2][3] (row first, counting from 0).
Flashcards
(12)What is an array?
What is a list?
Static or dynamic: which is an array and which is a list?
What is a two-dimensional array or list?
Where do row and column index numbers start?
How do you write a 2D list in Python?
What does one index in square brackets return from a 2D list?
Which comes first in a 2D list, the row index or the column index?
How do you replace one item in a 2D list?
How do you add a new row to a 2D list?
How do you find the average of one row of a 2D list?
How do you print a game board stored as a 2D list in grid form?
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 Edexcel GCSE Computer Science topics
How this lesson was checked. This Edexcel GCSE Computer Science (specification 1CP2)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 21 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.