Python list algorithms
Every UK GCSE Computer Science specification asks pupils to write standard algorithms over a list: totalling, counting, finding the smallest or largest value, searching for a target, and filtering into a new list. This unit shows the classic accumulator pattern (start with 0 or an empty list, loop and update) that underpins all of them. Every example runs in the browser so learners can trace the running total on each iteration. Perfect for classroom teaching, GCSE and A Level revision, and independent or home-schooled learners.
What you'll learn
- Sum a list with a for loop and a running total
- Count items that match a condition
- Find the min/max by tracking the best so far
- Perform a linear search for a target value
- Build a filtered list of items that match a condition
- Know the built-in equivalents: sum(), min(), max()
UK GCSE topic coverage
- Standard algorithms (sum)
- Standard algorithms (count)
- Standard algorithms (max)
- Standard algorithms (min)
- Linear search
- Standard algorithms (filter)
- Reusable list helpers
- Applied list algorithms
Worked example
Count how many scores are 50 or above
scores = [42, 55, 70, 33, 80, 51]
count = 0
for s in scores:
if s >= 50:
count = count + 1
print(count, "passed")Try a full unit free with a RunPy account
Sign up free and get the whole of Unit 1 (Input, Output and Variables) with checked tasks and instant feedback, plus a selection of the exam-style questions so you can practice on real GCSE-style content before upgrading.
Lessons in this unit
Full interactive lessons with checked tasks are available to signed-in RunPy users. Unit 1 and a selection of exam-style questions are free with a RunPy account.
- The accumulator: summing a list
- Counting with conditions
- Finding the maximum manually
- Finding the minimum manually
- Linear search
- Filtering into a new list
- List algorithms as functions
- Multi-algorithm challenge
Frequently asked questions
- What is a linear search?
- Looking through a list one item at a time until you find the target (or reach the end). It's the standard GCSE search algorithm; the other one you'll meet is binary search, which requires a sorted list.
- Should I use sum() or a manual loop?
- For real code, use the built-ins (sum, min, max). For GCSE exam questions asking you to 'write an algorithm', you often need to show the manual for-loop version to demonstrate understanding.
- What's the accumulator pattern?
- Start with a base value (0, empty list, first item), loop through the data, and update the accumulator on each pass. It's the shape shared by all the standard list algorithms.