Build lists, dicts, and sets in one readable expression from an iterable + filter.
Build a list, set or dict in one readable line instead of three lines of append-to-an-empty-container.
It's the most idiomatic thing in Python, and knowing when NOT to use one is what separates readable code from clever code.
A comprehension builds a collection in a single expression from an iterable, an optional filter, and a per-element transform. The same syntax builds lists ([...]), dicts ({k: v ...}), and sets ({x ...}). It's the idiomatic replacement for the empty-collection-plus-append loop, when the logic stays simple.
A comprehension collapses the build-an-empty-collection-then-loop-and-append pattern into one expression: [f(x) for x in items if cond]. Switch the brackets to braces and you get dict and set comprehensions. It's more readable and usually faster than the manual loop for simple map-and-filter work—but once the logic nests deeply or has side effects, a plain loop is clearer. I also keep the four core containers straight: list is ordered and mutable, tuple is an immutable record, set holds unique items, dict maps keys to values.
Tutorial 17- Python List Comprehension — Krish Naik, 8:07