Hi,
I started learning kdb+/q recently. I got a problem while create a dictionary.
According to the online guide, a dictionary could be created like this:
q)dict:`items`sales`prices!(items;sales;prices)
However, when I tried this:
q)dict:`items!(items)
I got error message: `type.
Anyone know why it is so? Thanks!
a dictionary is a map from one list to another.
hence the args must be lists/vectors, not scalars/atoms.
use enlist to form a list from a scalar.
As charlie described, a dictionary with one element needs to be enlisted, a shorthand for this might look like
d:d!d:enlist`items
SJT1
4
That does construct a singleton dictionary but the keys and values are the same, which might not be what the OP wanted.
q)show d:d!d:enlist`items items| items
Happily the 1 f\
Zen monks pattern can be used to convert a variable name into a dictionary of its name and its value.
q)items:cow
sheepcat
dog q).[!] enlist each 1 value`items items| cow sheep cat dog
Ill write more about the Zen monks soon.