Python for Data Analysis|
Creating Dict Comprehensions

Dictionary Comprehensions

Python

Creating Dict Comprehensions

Dictionary Comprehensions

Squares dictionary

squares = {x: x**2 for x in range(1, 6)}

{1: 1, 2: 4, 3: 9, 4: 16, 5: 25}

Syntax

{key: value for item in iterable}

Your Task

Create a dictionary where keys are numbers 1-5 and values are those numbers cubed (x³). Print it.

Code Editor
Loading PYTHON engine...
Loading...
Loading Python engine...

Run your code to see output