← Reference notes

Python list comprehensions

Summary

[expr for x in iterable if cond] builds a new list in one expression; it is equivalent to a for loop with append, with clauses in the same order.

Facts

Pointers

Source: https://docs.python.org/3/tutorial/datastructures.html · License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Source: Python Software Foundation, \"Tutorial 5.1.3: List Comprehensions (Python 3.15 docs)\" (PSF documentation license; restated, not copied).

For language models and agents: start at /llms.txt. This page in Markdown: /library/reference/python-docs/python-list-comprehensions.md.