Recommended Free Tools
Python’s dict() function creates a new dictionary. Use it with no arguments for an empty dictionary, with a mapping or iterable of key-value pairs to copy or convert data, or with keyword arguments for identifier-like string keys. If a key appears more than once, the later value replaces the earlier one.
What does dict() do?
dict() is Python’s dictionary constructor. A dictionary stores values under keys. The Python 3.14 Built-in Types documentation defines the constructor as returning “a new dictionary initialized from an optional positional argument and a possibly empty set of keyword arguments.”
Its documented forms are dict(**kwargs), dict(mapping, **kwargs), and dict(iterable, **kwargs). The positional argument is optional.
Create an empty dictionary
Call dict() without arguments:
settings = dict()
The empty dictionary literal {} creates the same kind of object and is often the clearest choice when writing dictionary data directly.
#1 Best Overall
Build a dictionary from existing data
From a mapping
Pass a mapping, such as another dictionary, to create a new dictionary with its key-value data:
from_mapping = dict({"debug": True, "retries": 3})
From an iterable of pairs
A positional input that is not a mapping must be an iterable whose items each contain exactly two elements: a key and its value.
from_pairs = dict([("name", "Ada"), ("language", "Python")])
Pair input can represent keys that cannot be written as keyword argument names:
Rank #2
labels = dict([("display name", "Ada"), ("user-id", 17)])
Each item must have exactly two elements. An item with too few or too many elements does not meet the constructor’s pair format.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteFrom keyword arguments
Keyword arguments provide a compact form when the keys are valid Python identifiers:
from_keywords = dict(debug=True, retries=3)
Because Python parses these names as keyword arguments, this syntax cannot express keys such as "display name" or "user-id". Use a mapping or pairs for those keys.
When a literal or comprehension is clearer
For key-value data written directly in source code, a dictionary literal makes the contents visible without constructor syntax:
person = {"name": "Ada", "language": "Python"}
When values are generated from a sequence or calculation, a dictionary comprehension expresses that transformation:
squares = {number: number * number for number in range(4)}
Choose according to the input: literals suit inline data, comprehensions suit generated entries, and dict() is useful for mappings, pair iterables, or keyword-based construction.
Duplicate keys: later values win
If the same key is provided more than once, Python keeps the last value rather than raising an error. This applies to repeated pairs and to keyword arguments supplied alongside a positional mapping or iterable.
options = dict([("mode", "safe"), ("mode", "fast")])
# {'mode': 'fast'}
options = dict({"mode": "safe"}, mode="fast")
# {'mode': 'fast'}
This behavior lets keyword arguments override defaults, but it can also hide accidental duplicate data.
Dictionary order after construction
Dictionaries preserve insertion order. Replacing the value for an existing key leaves that key in its current position. If you delete a key and later insert it again, it appears at the end.
Best Value
Use update() or merge operators for existing dictionaries
dict() creates a new dictionary. If the goal is to add or replace entries in an existing one, use update() or an in-place merge instead.
| Operation | Effect | Returns | Version note |
|---|---|---|---|
target.update(data) |
Mutates target; accepts a mapping or iterable of key-value pairs and overwrites matching keys. |
None |
No version restriction noted here. |
left | right |
Creates a merged dictionary. | A new dictionary | Added in Python 3.9. |
left |= right |
Updates left in place. |
In-place operation | Added in Python 3.9. |
Use | when you want a separate merged result, and |= or update() when you want to modify the existing dictionary. The merge operators are not available in Python versions earlier than 3.9.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




