dict

Syntax

dict(keyObj, valueObj, [ordered=false])

or

dict(keyType, valueType, [ordered=false])

Arguments

keyObj a vector indicating dictionary keys.

valueObj a vector indicating dictionary values.

keyType the data type of dictionary keys. The following data categories are supported: Integral (excluding COMPRESS), Temporal, Floating and Literal.

valueType the data type of dictionary values. Note that COMPLEX, POINT and the Decimal category are not supported.

ordered a Boolean value. The default value is false, which indicates to create a regular dictionary. True means to create an ordered dictionary. The regular dictionaries do not track the insertion order of the key-value pairs whereas the ordered dictionaries preserve the insertion order of key-value pairs.

Details

Return a dictionary object.

Examples

$ x=1 2 3
$ y=4.5 7.8 4.3
$ z=dict(x,y);
$ z;
3->4.3
1->4.5
2->7.8

$ z=dict(INT,DOUBLE);
$ z[5]=7.9;
$ z;
5->7.9

$ z[3]=6;
$ z;
3->6
5->7.9

$ dt=dict([`test], [1]);
$ dt;
test->1

//create an ordered dictionary
$z=dict(x,y,true)
$z;
1->4.5
2->7.8
3->4.3

To get keys and values of a dictionary:

$ x=1 2 3
$ y=4.5 7.8 4.3
$ z=dict(x,y);

$ z.keys();
[3,1,2]

$ z.values();
[4.3,4.5,7.8]

related system functions: array, matrixdictUpdate!, syncDict