All lessons

Power Tools: map, filter & Comprehensions

9 min · Python

Python's shortcuts for transforming and filtering a list in one line.

Python · Power Tools: map, filter & Comprehensions0/5 cleared

Enemy 1 of 5

A list comprehension builds a new list in one line: [expression for item in iterable]. It's shorthand for a for loop that appends to a list.

Run this to build a list of squares without writing out the loop.

You
Syntax Skeleton

Loading editor...

Ln 1, Col 1Spaces: 4
Sign up to fightTarget output: [0, 1, 4, 9, 16]