List comprehensions: a quick way to create lists in Python

Опубликовано: 31 Май 2026
на канале: PatchyPython
165
1

Try this code in your browser: click here
https://tinyurl.com/5cud7uzd

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 on comprehensions and lists and to try out the code, click on the link above - a notebook will open in your browser, no need to install Python on your machine.

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