Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
List Comprehensions | List
Python Data Structures

List ComprehensionsList Comprehensions

Hi, welcome to the last but certainly not least chapter of the section on list functionality. List comprehensions are one of the favorite Pythonic ways for Python developers to create lists in a single line.

In essence, list comprehensions can be used to generate lists by applying functions to each element in the list.

Here is the general syntax:

For example:

This is roughly equivalent to the for-loop:

List Comprehansions with Conditions

You can also use conditions:

For example:

Which is equivalent to:

Let's practice:

Task

Suppose you have a list of temperatures in Fahrenheit and you want to convert them to Celsius.

Everything was clear?

Section 1. Chapter 11
toggle bottom row
course content

Course Content

Python Data Structures

List ComprehensionsList Comprehensions

Hi, welcome to the last but certainly not least chapter of the section on list functionality. List comprehensions are one of the favorite Pythonic ways for Python developers to create lists in a single line.

In essence, list comprehensions can be used to generate lists by applying functions to each element in the list.

Here is the general syntax:

For example:

This is roughly equivalent to the for-loop:

List Comprehansions with Conditions

You can also use conditions:

For example:

Which is equivalent to:

Let's practice:

Task

Suppose you have a list of temperatures in Fahrenheit and you want to convert them to Celsius.

Everything was clear?

Section 1. Chapter 11
toggle bottom row
some-alt