Filtering a stream of records
Keep only the records in a stream that meet a condition and discard the rest, usually with an if inside a loop that adds matches to a result list.
Understanding Filtering a stream of records in QCE Digital Solutions Unit 2
What it does: The empty list collects matches, the for loop visits each record, and the if inside the loop decides which records are appended. Filtering selects records. It does not change them. Records that fail the condition are left out of the result. and needs BOTH tests to be true. or would also keep Year 10 students with high points and Year 11 students with low points. A single = assigns a value. A condition needs the comparison operator == to test equality. The and operator joins two tests, so a record must satisfy both to pass the filter.
Common mistakes: The condition is reversed. <= keeps students with 50 or less, so the passed list would hold the failures. It should be >= 50 so that only students who passed are kept. A for loop header must end with a colon. It should be for p in people: so the indented filter code forms the loop body.
Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 186–228) and word search (Modules 144–228).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
filterFill in the Blanks
Spot the Error
Student with a class code? Join your class →