🐍 Paper 2 · Topic 6: Programming
6.3a Lists in Python
Edexcel 1CP2 · GCSE Computer Science · ~11 min read · 🆓 Free
Notes
──
Video
──
Slides
──
Worksheet
──
Quiz

What is a List?

A list in Python is an ordered, mutable (changeable) collection of items. Items can be of different data types. Lists are defined using square brackets [] and items are separated by commas.

# Creating lists numbers = [10, 20, 30, 40, 50] names = ["Alice", "Bob", "Charlie"] mixed = [42, "hello", True, 3.14] # different types empty = [] # empty list

Accessing Items

Items are accessed using their index (starting at 0). Negative indices count from the end.

colours = ["red", "green", "blue", "yellow"] print(colours[0]) # "red" print(colours[2]) # "blue" print(colours[-1]) # "yellow" (last item) print(colours[-2]) # "blue" (second from last)

List Methods

MethodWhat it doesExample
.append(x)Adds x to the END of the listnums.append(6)
.insert(i, x)Inserts x at position inums.insert(0, 99)
.remove(x)Removes first occurrence of xnums.remove(20)
.pop()Removes and returns last itemlast = nums.pop()
.sort()Sorts list in ascending order (in place)nums.sort()
.reverse()Reverses list in placenums.reverse()
.index(x)Returns index of first occurrence of xnums.index(30)
len(list)Returns number of itemslen(nums)
scores = [85, 72, 91, 64] scores.append(78) # [85, 72, 91, 64, 78] scores.sort() # [64, 72, 78, 85, 91] print(scores[0]) # 64 — lowest score print(scores[-1]) # 91 — highest score print(len(scores)) # 5

Iterating Over Lists

A for loop is ideal for processing every item in a list:

fruits = ["apple", "banana", "cherry"] for fruit in fruits: print(fruit) # prints each fruit # Using index with range for i in range(len(fruits)): print(i, fruits[i]) # 0 apple, 1 banana, 2 cherry

Searching Lists

nums = [10, 20, 30, 40] if 20 in nums: print("Found!") # use 'in' to test membership # Linear search — find position manually target = 30 for i in range(len(nums)): if nums[i] == target: print("Found at index", i)

2D Lists (Nested Lists)

A list can contain other lists — useful for grids, tables, or matrices:

grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] print(grid[0][0]) # 1 — row 0, column 0 print(grid[1][2]) # 6 — row 1, column 2 print(grid[2][1]) # 8 — row 2, column 1
Exam tip: Lists are the Python equivalent of arrays in Edexcel pseudocode. Common exam tasks include: finding the maximum/minimum value, counting occurrences, searching for an item, and calculating totals/averages. Always practise writing loops over lists.
⚠️ Common Mistakes
  • Index out of range error — if a list has 5 items, valid indices are 0–4 (NOT 5)
  • Confusing .append() (adds one item to end) with .insert() (adds at specific position)
  • Forgetting .sort() modifies the list IN PLACE — it does not return a new sorted list
  • Modifying a list while iterating over it can cause unexpected behaviour
  • 2D list indexing is grid[row][column] — row first, then column
Video coming soon
Click slide or press arrow keys to navigate
✍️

Worksheet — 6.3a Lists in Python

8 Edexcel-style questions · instantly marked

Q1Given: items = ["pen", "book", "ruler", "eraser"]. What is the output of print(items[2]) and print(items[-1])?[2]
✅ Mark scheme
items[2] = "ruler" [1]; items[-1] = "eraser" [1]. Index 2 is the third item (0-indexed). Negative index -1 is always the last item.
Q2Write Python code to create an empty list called 'students', then add three names to it using .append().[4]
✅ Mark scheme
students = [] [1]; students.append("Alice") [1]; students.append("Bob") [1]; students.append("Charlie") [1]. (Accept any valid names. .append() adds to the end of the list each time.)
Q3Write a for loop to print every item in: colours = ["red", "green", "blue", "yellow"][2]
✅ Mark scheme
for colour in colours: [1]; print(colour) [1] — indented under the for loop. (Accept: for c in colours / for i in range(len(colours)): print(colours[i]) — any valid loop.)
Q4What is the difference between .append() and .insert() in Python lists?[2]
✅ Mark scheme
.append(x) adds item x to the END of the list [1]; .insert(i, x) inserts item x at a specified index i, shifting existing items right [1]. Example: list.insert(0, "x") adds "x" to the front.
Q5Write Python code that: creates a list of 5 numbers, then calculates and prints the total (sum) and average.[5]
✅ Mark scheme
nums = [10, 20, 30, 40, 50] or any 5 numbers [1]; total = 0 [1]; for n in nums: total += n [1]; print(total) [1]; print(total / len(nums)) [1]. (Accept: using sum() built-in: total = sum(nums), average = total/len(nums).)
Q6What does the following code output? grid = [[1,2],[3,4],[5,6]]; print(grid[1][0])[2]
✅ Mark scheme
3 [2]. grid[1] accesses the second sub-list [3,4] [1 for understanding]; [0] then gets the first element = 3 [1]. 2D list is indexed [row][column].
Q7Write a program that asks the user for 5 numbers (one at a time), stores them in a list, sorts the list, then prints it.[5]
✅ Mark scheme
nums = [] [1]; for i in range(5): [1]; n = int(input("Enter a number: ")) [1]; nums.append(n) [1]; nums.sort() [1]; print(nums). (Must use int() to convert input since input() returns a string.)
Q8Write a linear search function that takes a list and a target value as parameters, and returns the index if found or -1 if not found.[4]
✅ Mark scheme
def linear_search(lst, target): [1]; for i in range(len(lst)): [1]; if lst[i] == target: return i [1]; return -1 [1]. The return -1 must be OUTSIDE the loop (correct indentation critical). -1 is a conventional way to signal "not found".
Topic Quiz
Q 1 of 15
You scored
out of 15
Click to reveal definition
🎉
Session complete!
TermDefinition
🎯

Mini Test — Lists in Python

Timed exam-style test — 10 minutes.

← 6.2b Logical & String OpsTopic 6 · PythonNext: 6.3b Tuples & Dicts →