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 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:

Tarefa

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

Tudo estava claro?

Seção 1. Capítulo 11
toggle bottom row
course content

Conteúdo do Curso

Python Data Structures

List 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:

Tarefa

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

Tudo estava claro?

Seção 1. Capítulo 11
toggle bottom row
some-alt