SLIDE 1
CSZone.co.uk
Click to advance · Arrow keys also work
Edexcel 1CP2 · Topic 6 · 6.3a

Lists
in Python

Indexing · append() · remove() · sort() · Traversal · 2D Lists

CSZoneEdexcel GCSE Computer Science 1CP2
Creating & Accessing Lists

Ordered Collections

scores = [85, 72, 91, 68, 77]

print(scores[0]) # 85 (first element)
print(scores[-1]) # 77 (last element)
print(scores[1:3]) # [72, 91] (slice)
print(len(scores)) # 5

scores[2] = 95 # modify element
Lists are mutable: you can change, add, and remove elements — unlike strings
Lists can hold mixed types: [1, "Alice", True, 3.14]
List Methods

Modifying Lists

names = ["Alice", "Bob", "Charlie"]

names.append("Diana") # add to end
names.insert(1, "Eve") # insert at index 1
names.remove("Bob") # remove by value
names.pop() # remove last item
names.sort() # sort alphabetically
print(names.index("Alice")) # find index
append(): most common way to add items; insert(i, val): add at specific position
sort(): sorts in place (ascending); sorted(list): returns a sorted copy
min(), max(), sum(): work on numeric lists
Traversal & 2D Lists

Looping Through Lists

# Traversal with for loop
for score in scores:
print(score)

# 2D list (like a table/grid)
grid = [[1,2,3], [4,5,6], [7,8,9]]
print(grid[1][2]) # 6 (row 1, col 2)
for row in grid:
for item in row:
print(item, end=" ")
2D list: list of lists — used for grids, tables, game boards
Access with two indices: grid[row][col]
Exam Practice

Have a go at this question

Edexcel-style question
Write Python code that asks the user to enter 5 numbers, stores them in a list, and then prints the highest value.
4 marks
numbers = []
for i in range(5):
num = int(input("Enter number: "))
numbers.append(num)
print("Highest:", max(numbers))
Key Takeaways

What to Remember

Lists: ordered, mutable, zero-indexed; can hold mixed types
Methods: append(), insert(), remove(), pop(), sort(), index()
Traversal: for item in list — iterates through each element
2D lists: list of lists; access with grid[row][col]; useful for tables and grids