dict merge

Joins dicts into one, with the value of a later dict for a key in both.

dict merge ?DICT ...?

Description

Gives one dict with each key of each DICT. For a key in more than one DICT, the value of the last one wins, and the key keeps the place of its first one. The merge is one level deep: a nested dict is a value, and a later one replaces it as a whole. With no DICT it gives an empty dict.

Arguments

ArgumentTypeDefaultDescription
DICTdictnoneA dict to join.

Returns

The new dict.

Examples

% dict merge {a 1 b 2} {b 3 c 4}
a 1 b 3 c 4

% dict merge {a {x 1}} {a {y 2}}
a {y 2}

% dict merge

Errors

% dict merge {a 1} {b}
missing value to go with key
-errorcode NONE

Facts

Capability
None.
Tcl release
Tcl 9.1 and 8.6.
Since
ztcl 1.0.0-beta.1

See also