List Comprehension

Learn how to create a new list by using loops to process each item from an existing list.

List comprehension is a technique that uses a for loop and optionally a condition to create a new list from an existing one. The result is always a new list, so it’s good practice to assign a 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 1400+ tech skills courses.