Creating a blank dictionary structure
To create a new dictionary structure that contains some or all of the key/value mappings present in an existing dictionary, Tcl provides the dict remove
command. The syntax is as follows:
dict remove dictionayValue key1… key2…
How to do it…
In the following example we will create a dictionary containing collections of key/value pairs and then using the dict remove
command create a new dictionary containing a portion of the key/value pairs. Return values from the commands are provided for clarity. Enter the following command:
% set test [dict create 1 John 2 Mary 3 Paul] 1 John 2 Mary 3 Paul % set new [dict remove $test 2] 1 John 3 Paul
How it works…
As you can see, the dict remove
command has created a new dictionary that contains only the desired key/value pairs. In our example, the key/value pair for key 2
was removed.