To more effectively interact with a dictionary, it is beneficial to know how many entries are contained within. To accomplish this, Tcl provides the dict size
command. The syntax is as follows:
dict size dictionaryValue
In the following example, we will create a dictionary containing collections of key/value pairs and then we will use the dict size
command to determine the number of 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
% dict size $test
3
52.15.245.1