dict()

dict(**kwargs) / dict(mapping) / dict(iterable)
Returns: dict · Updated March 13, 2026 · Built-in Functions
built-in mapping container dictionary

The dict() function creates a new dictionary object in Python. Dictionaries are mutable, unordered collections of key-value pairs, where each key must be unique and hashable.

Syntax

dict(**kwargs)
dict(mapping)
dict(iterable)

Parameters

ParameterTypeDefaultDescription
**kwargskeyword argumentsCreate dictionary from key=value pairs
mappingmapping objectCreate dictionary from another mapping (e.g., dict from dict)
iterableiterableCreate dictionary from an iterable of key-value pairs

Examples

Creating an empty dictionary

# Two equivalent ways to create an empty dict
empty1 = {}
empty2 = dict()
print(empty1, empty2)
# {} {}

Using keyword arguments

# Most common way to create a dict with values
person = dict(name="Alice", age=30, city="London")
print(person)
# {'name': 'Alice', 'age': 30, 'city': 'London'}

From a mapping object

# Create from another dict
original = {"a": 1, "b": 2}
copy = dict(original)
print(copy)
# {'a': 1, 'b': 2}

# Create from any mapping-like object
from collections import OrderedDict
od = OrderedDict([('first', 1), ('second', 2)])
d = dict(od)
print(d)
# {'first': 1, 'second': 2}

From an iterable of key-value pairs

# From a list of tuples
pairs = [("name", "Bob"), ("age", 25), ("skills", ["Python", "SQL"])]
user = dict(pairs)
print(user)
# {'name': 'Bob', 'age': 25, 'skills': ['Python', 'SQL']}

# From a generator expression
keys = ["x", "y", "z"]
values = [10, 20, 30]
d = dict(zip(keys, values))
print(d)
# {'x': 10, 'y': 20, 'z': 30}

Common Patterns

Dictionary comprehension alternative

# dict() with zip vs comprehension
keys = ["a", "b", "c"]
values = [1, 2, 3]

# Using dict()
d1 = dict(zip(keys, values))

# Using comprehension
d2 = {k: v for k, v in zip(keys, values)}

print(d1, d2)
# {'a': 1, 'b': 2, 'c': 3} {'a': 1, 'b': 2, 'c': 3}

Converting list of values to dict with default keys

# Map list values to dictionary with index as key
items = ["apple", "banana", "cherry"]
indexed = dict(enumerate(items))
print(indexed)
# {0: 'apple', 1: 'banana', 2: 'cherry'}

When to Use dict()

  • Creating dictionaries with known keys at initialization
  • Copying or converting from other mappings
  • Building dictionaries from parallel sequences with zip()

See Also