dict()

Initializes a new dictionary from mapping n-number of object (key, value) pairs.

Syntax

dict(key-value pairs)

Example 1

Use dict() to create the my_dict dictionary from a list of tuples:

Code
Output
Loading...

Example 2

Use dict() to create the my_dict dictionary from keyword arguments:

Code
Output
Loading...

Example 3

Use dict() to create the d dictionary using list comprehension:

Code
Output
Loading...

Example 4

Use dict() to create the new empty dictionary d:

Code
Output
Loading...

Contributors

Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.

Learn Python on Codecademy

Contributors