Skip to main content
Loading page…
Python Mastery
Chapter 16
Lesson 1 of 4
Comprehensions
Contents
Notes
Tutor
Concept
The Accumulator Problem
Loading activity…
Previous
1 / 8
Continue
Contents
Notes
Discussion
Tutor
28 min
8 activities
0 of 8 done
In this lesson
1
The Accumulator Problem
2
Filtering and Transforming in One Pass
3
Dict and Set Comprehensions
4
Nested Comprehensions — Matrix Transposition
5
Check: Filter vs. Conditional Expression
6
The Readability Cliff
7
Practice: Census Data Cleanup
8
Comprehension vs. Loop — Justify Your Choice
Objectives
Write list, dict, and set comprehensions with filter conditions
Refactor a for-loop accumulator into an equivalent comprehension
Nest comprehensions correctly and recognise when nesting hurts readability
Choose between a comprehension and a plain loop based on clarity
Chapter 16 · Iterators, Generators & Comprehensions
Comprehensions
Iterables & Iterators
Generators & yield
itertools, map, filter
Previous: Metaclasses
Next: Iterables & Iterators