PYTHON INTERMEDIATEChapter 6 · Comprehensions and data tools
List comprehensions
A list comprehension is a concise way to create lists. It replaces standard loops with a single line: [expression for item in iterable if condition].
Worked example
How it reads
- **[x * 2 for x in nums]** loops through nums and returns doubled values
- if x % 2 == 0 filters the input list keeping only evens

Cloud tip: Comprehensions are faster and more readable, but do not make them too complex or nested.


