Track 6 · Lesson 9 of 12
Comprehensions: building collections in one line
Write list, dict and set comprehensions with filters, and know when a plain loop is clearer.
You will be able to
- Rewrite a build-a-list loop as a list comprehension
- Filter items with an if clause and transform them with an expression
- Build dictionaries and sets with dict and set comprehensions
- Recognise when a comprehension hurts readability and a loop is better
Included with a Formula Quest membership
It has 5 graded exercises with feedback, hints and solutions. Python Quest is included in Formula Quest memberships that cover Python; membership and billing are managed on Formula Quest.
View Formula Quest memberships
Tracks 1 and 2, the first lesson of every track, the playground and the dataset library are free.