To create an empty associative array, use the Associative Array() function or [=>].
If there is no default value, Empty() is returned.
Besides the Set Default Value message, a default value can be set in the literal constructor using =>value without a key.
In the first line, the default value is set to 0. In the second line, the key "c" does not exist in counts. In the output, the key "c" is created with the default value of 0 and then incremented by 1.
Insert() and Remove() return a named copy of the given associative array with the key-value pair added or removed.
Insert Into() and Remove From() add or remove the key-value pairs directly from the given associative array.
Insert() and Insert Into() take three arguments: the associative array, a key, and a value.
Remove() and Remove From() take two arguments: the associative array and a key.
The following examples illustrate Insert() and Insert Into():
Note that aa << Insert is a message sent to an associative array that does the same thing as the function Insert Into(). For example, these two statements are equivalent:
The following examples illustrate Remove and Remove From:
Note that aa << Remove is a message sent to an associative array that does the same thing as the function Remove From(). For example, these two statements are equivalent:
To see a value for a single key, use the <<Get Value message. Specify only one key and do not place it in a list.
Note: Using the <<Get Contents message, the returned list does not include the default value. Keys are listed alphabetically.
To iterate through as associative array, use the <<First and <<Next messages. <<First returns the first key in the associative array. <<Next(key) returns the key that follows the key that is given as the argument.
A key can exist only once in an associative array, so putting a column’s values into one automatically results in the unique values. For example, the Big sample data table contains 40 rows. To see how many unique values are in the column height, run this script:
There are only 17 unique values for height. You can use those unique values by getting the keys:
Because keys are ordered lexicographically, putting the values into an associative array also sorts them. For example, the <<Get Keys message returns the keys (unique values of the names column) in ascending order:
Use N Items() to see how many countries appear in each data table:
Use the <<Intersect message to find the common values:
This is a two-level associative array. The associative array g contains five associative arrays (1, 2, 3, 4, and 5). In the containing array g, both the keys (1-5) and the values (the arrays that define the map) are important. In the inner associative arrays, the values do not matter. Only the keys are important.
Example of a Directed Graph
Given a list of names, which of them are not contained in Big You can find the answer by taking the difference of the two sets of names.