List comprehensions: a quick way to create lists in Python

Опубликовано: 19 Ноябрь 2024
на канале: PatchyPython
133
1

Comprehensions are an effective way to build lists using a notation reminiscent of set theory.
They are one of the nicest concepts Python borrowed from Functional programming, and they allow you to write code that's both compact and fast. In this video I show you how to create a comprehension, and how to use the "if" keyword as a filter to specify conditions that the elements of the final list must satisfy. For more information, see the notebooks below (notebooks will open on Google Colab - no installation required)

Embedded video, part of the following courses:
Computer Programming at Queen Mary, University of London
Jupyter notebook: https://tinyurl.com/3xjmpf94
Coding for Scientists at Queen Mary, University of London
Jupyter notebook: https://tinyurl.com/yedumefr