dict
Dictionary operations for key-value data structures.
Syntax
dict subcommand ?arg ...?Subcommands
dict create
dict create ?key value ...?Creates and returns a new dictionary with the specified key-value pairs.
dict get
dict get dictionary ?key ...?Returns the value for the specified key. Multiple keys navigate nested dictionaries.
dict set
dict set dictVarName key ?key ...? valueSets a value in the dictionary variable. Multiple keys create nested dictionaries.
dict exists
dict exists dictionary key ?key ...?Returns 1 if the key exists, 0 otherwise. Multiple keys check nested dictionaries.
dict keys
dict keys dictionary ?pattern?Returns a list of all keys. Optional glob pattern filters results.
dict values
dict values dictionary ?pattern?Returns a list of all values. Optional glob pattern filters results.
dict size
dict size dictionaryReturns the number of key-value pairs in the dictionary.
dict remove
dict remove dictionary ?key ...?Returns a new dictionary with the specified keys removed.
dict replace
dict replace dictionary ?key value ...?Returns a new dictionary with values replaced for the specified keys.
dict merge
dict merge ?dictionary ...?Merges multiple dictionaries. Later dictionaries override earlier ones.
dict append
dict append dictVarName key ?value ...?Appends values to the string value for the specified key in the variable.
dict incr
dict incr dictVarName key ?increment?Increments the integer value for the specified key. Default increment is 1.
dict lappend
dict lappend dictVarName key ?value ...?Appends values to the list value for the specified key in the variable.
dict unset
dict unset dictVarName key ?key ...?Removes the specified key from the dictionary variable. Multiple keys for nested.
dict for
dict for {keyVar valueVar} dictionary bodyIterates over the dictionary, binding each key and value to variables.
dict info
dict info dictionaryReturns an implementation-specific information string about the dictionary.
dict getdef
dict getdef dictionary ?key ...? key defaultGets the value for the key, returning the default if the key doesn't exist.
Examples
Creating and accessing dictionaries
Modifying dictionaries
Iterating over dictionaries
Using dict getdef for defaults
See Also
- list - List operations
