Home / Glossary / List Comprehension
PythonList Comprehension
Compact syntax to build a list from an iterable.
List comprehensions replace verbose for-loops with a one-line expression. They are idiomatic Python and often faster than equivalent loops.
Example
returns = [p/prices[i-1]-1 for i, p in enumerate(prices[1:], 1)]