Transforming a stream of records
map() applies a function to every record in a stream and gives back changed records, such as converting a type, trimming and changing the case of text, or computing a derived field.
Understanding Transforming a stream of records in QCE Digital Solutions Unit 2
What it does: The comprehension applies float() to the price field of each record, giving back changed values. The new total field is computed from the price and qty fields, so it is a derived field. Values read from a file arrive as text. Converting the type, such as float("12.50"), is a transform that lets you do maths on the value. strip() removes spaces from both ends and title() capitalises each word, giving "Ava Nguyen". This is a trim and change-case transform. map() changes each record but never drops any. Removing records is the job of filtering. Changing everything to lower case makes the values consistent so they match when compared. strip("red") would remove letters instead.
Common mistakes: map() needs the function itself, not a call to it. int() with no argument raises an error. It should be map(int, rows), which converts each string to an integer. The list is missing its closing square bracket. The line should end with ] so the list of raw names is complete before each one is trimmed and title-cased.
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
mapFill in the Blanks
Spot the Error
Student with a class code? Join your class →