CKTIS / Python
Dictionary unpacking
The expression {**a, **b} creates a new dictionary from the items of two mappings. For repeated keys, the later value wins; the source dictionaries remain unchanged.
Version: Python 3.14; repository image, production runtime not attested
Syntax
{**a, **b}{**a, **b} creates a new dictionary: **a inserts key–value pairs from mapping a, and **b from mapping b. Each ** operand must be a mapping; being iterable, such as a list of pairs, is not enough.
Items are processed from left to right. If a key occurs again, the later value replaces the earlier one without an error. Unpackings can be mixed with ordinary pairs, as in {**a, 'count': 5, **b}: the last value for a key still wins.
The result is a new dictionary, not a deep copy: nested objects remain shared. The merge itself does not change a or b. Keys retain their first-insertion order; replacing a value does not move its key to the end.
In the example, b replaces the value of 'color', and 'enabled' is added at the end. The final print shows that a['color'] is still 'blue'.
Examples
a = {'color': 'blue', 'count': 2}
b = {'color': 'green', 'enabled': True}
merged = {**a, **b}
print(merged)
print(a['color'])Result
{'color': 'green', 'count': 2, 'enabled': True}
blue
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.