UNIT 02 · TOPIC 20
List Comprehensions
A list comprehension builds a new list from an iterable, optionally filtering items.
The idea
List Comprehensions, simply explained
A list comprehension builds a new list from an iterable, optionally filtering items.
01
See the big picture
How the idea flows
Read the diagram as a simple path: begin with a problem, use the Python idea, then verify the result.
02
Everyday connection
Real-life example
↗
A coach creates a new list containing only players who scored above a target.
03
Learn by doing
Python code example
PYTHONExample
scores = [42, 78, 91, 65]
passed = [score for score in scores if score >= 70]
print(passed)Expected result
[78, 91]Try it: Change one value in the code, predict what will happen, then run it and compare your answer.
04
Keep this in mind
Key takeaways
- A list comprehension builds a new list from an iterable, optionally filtering items.
- Think of a real problem where list comprehensions could save time or organize information.
- Test small changes and read the result carefully before moving to a bigger program.
Quick self-check
Can you explain it in your own words?
What is the main idea of List Comprehensions?
A list comprehension builds a new list from an iterable, optionally filtering items.
Where could you see this idea in everyday life?
A coach creates a new list containing only players who scored above a target.
