networktestinggenius.tk
Your networking tutor
Exclusive networking testing notes
Learn Networking & Testing topics

Dictionaries
The dict commands implement a paired list data structure in which a key and value are guaranteed to maintain their relationship and order of the indices is maintained.
This is like a merger of an associative array (key/value pairs) and the list (ordered data) structures. An associative array guarantees that the value associated with a given index won't change (unless an application changes it) but doesn't guarantee the order of indices. A list guarantees that the elements won't change order (again unless your code changes things) but doesn't show how one value is related to another.
The dict command has several subcommands. The critical ones are:
dict create ?key val? ?key val?
Create a new dict and return values to be assigned to a variable.
You may have zero or more key and value pairs, but the every key must have a value.
dict set dictName key val
Assign a new key/value pair to the dictionary named dictName. You can only assign values to a single key at a time. If there are multiple key/value pairs, you must be creating a new index, and the values will be treated as nested dicts. See the lesson on nested dicts for more information. Note that set uses a variable name, not the value.
dict get $dictName key
Return the value associated with the key in the dictionary. Only one key can be queried at a time.
dict size $dictName
Return the number of key/value pairs in the dictionary.
dict keys $dictName ?pattern?
Return a list of the keys in the dictionary. Optionally, only the keys that match a pattern.
dict values $dictName
Return a list of the patterns in a dictionary. Optionally, only the values that match a pattern.