CodeAgeBy Sitezack
Final project: data pipelineFrom raw data to report0 XP
Chapter progress0/6

Lesson 4 of 6

Transform with comprehensions

A list comprehension expresses a transformation in one line: [f(x) for x in xs].

With a conditional expression, it categorises: "high" if score >= 100 else "low".

levels = ["high" if r["score"] >= 100 else "low" for r in records]

🎯 Exercise

From records (provided), build in one comprehension the levels list: "high" if the score is greater than or equal to 100, otherwise "low". Print levels.

PRO lesson

This advanced chapter is part of CodeAge PRO. Unlock it to keep your adventure going.

Discover PRO