List Comprehension

Let's learn how to create a new list from an existing list using for loops.

Definition #

List comprehension is a technique that uses a for loop and a condition to create a new list from an existing one.

The result is always a new list, so it’s a good practice to assign list comprehension to a new variable.

Structure #

A list comprehension statement is always enclosed in square brackets, [].

The comprehension consists of three main parts:

Get hands-on with 1200+ tech skills courses.