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.
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 rangefor i inrange(len(fruits)):print(i, fruits[i]) # 0 apple, 1 banana, 2 cherry
Searching Lists
nums = [10, 20, 30, 40]if20in nums:print("Found!") # use 'in' to test membership# Linear search — find position manuallytarget = 30for i inrange(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:
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
✅ Notes completed!
▶
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!
Term
Definition
🎯
Mini Test — Lists in Python
Timed exam-style test — 10 minutes.
⏱10:00
Section A — Multiple Choice [5 marks]
Q1What is the index of the first item in a Python list?[1]
Q2Which method adds an item to the END of a list?[1]
Q3nums = [3, 1, 4, 1, 5]. What does len(nums) return?[1]
Q4What does grid[0][1] access in a 2D list?[1]
Q5Which keyword checks if an item exists in a list?[1]
Section B — Short Answer
Q6Write Python code to find and print the largest number in a list called 'values' without using the max() function.[3]
Mark schemelargest = values[0] [1]; for v in values: [1]; if v > largest: [1]; largest = v [1]; print(largest) [1 bonus]. Sets initial maximum to first element, then checks each remaining element.
Q7Explain what a 2D list is and give one real-world use case.[2]
Mark schemeA 2D list is a list that contains other lists as its elements [1]; Real-world use: storing a seating plan / noughts and crosses grid / spreadsheet data / pixel colours in an image / student grades table [1 — any valid example].