Lesson 14 of 55
PythonList Comprehensions
20 minutes
Course progress25%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 14 of 55
Python20 minutes
Keep these ideas in mind as you work through the lesson.
List comprehensions provide a concise way to create lists from existing iterables, optionally filtering or applying an expression.
# Squares of numbers 0‑9
squares = [x * x for x in range(10)]
print(squares)
# Filtering even numbers from 0‑19
evens = [x for x in range(20) if x % 2 == 0]
print(evens)
The general syntax is [expression for item in iterable if condition].