Appending to a dictionary
One way of adding key/value pairs to a dictionary is the dict append
command. The syntax is as follows:
dict append name key value…
How to do it…
In the following example, we will create a dictionary containing a set of key/value pairs and then append an additional set. Return values from the commands are provided for clarity. Enter the following command:
% set names [dict create 1 John 2 Mary 3 Paul] 1 John 2 Mary 3 Paul % dict append names 4 Fred 1 John 2 Mary 3 Paul 4 Fred
How it works…
The dict append
command appends a key and value
pair (or pairs) to the dictionary referenced by name
.