Skip to content

Glossary: Python Beyond the Basics

list comprehension

Also written: comprehension, dict comprehension, set comprehension, comprehensions

A one-line way to build a list, dict or set from another collection, such as `[price * 1.2 for price in prices]`. A trailing `if` filters; `A if cond else B` at the front picks a value per item.

Where the book teaches it

Related terms

generator expression