A list comprehension constructs a list by applying an expression to elements selected through generators and optional predicates. In Python,
[x*x for x in range(5) if x % 2 == 0] gives [0, 4, 16]. The generator sets the traversal, the predicate filters values and the expression transforms those retained. Nested generators preserve an order, so changing them can change output order and termination for infinite inputs in lazy languages. A Python list comprehension constructs the whole result eagerly; a generator expression instead produces values on demand.[ref] New to topics? Read the docs here!