Add an if clause to filter elements: [expression for item in iterable if condition]. Only items where the condition is true are included.
Given nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]: python evens = [n for n in nums if n % 2 == 0] # Result: [2, 4, 6, 8, 10] You can combine transformation and filtering: squared_evens = [n ** 2 for n in nums if n % 2 == 0] gives [4, 16, 36, 64, 100].
Only even numbers, then squared. Multiple conditions use and/or: [n for n in nums if n > 3 and n < 8] returns [4, 5, 6, 7]. This replaces multi-line loops with a single expressive line.