!
Dict¶
Make a dictionary or keyed table; remove a key from a table
x!y ![x;y]
Where
x
andy
are same-length lists, returns a dictionary in whichx
is the key andy
is the valuey
is a simple table andx
is a member of1_til count y
, returns a keyed table with the firstx
columns as its keyy
is a table andx
is 0, returns a simple table; i.e. removes the key
Dictionary keys should be distinct (i.e. {x~distinct x}key dict)
but no error is signalled if that is not so.
Items of x
and y
can be of any datatype, including dictionaries and tables.
q)`a`b`c!1 2 3
a| 1
b| 2
c| 3
q)show kt:2!([]name:`Tom`Jo`Tom; city:`NYC`LA`Lagos; eye:`green`blue`brown; sex:`m`f`m)
name city | eye sex
----------| ---------
Tom NYC | green m
Jo LA | blue f
Tom Lagos| brown m
q)show ku:([]name:`Tom`Jo`Tom; city:`NYC`LA`Lagos)!([]eye:`green`blue`brown; sex:`m`f`m)
name city | eye sex
----------| ---------
Tom NYC | green m
Jo LA | blue f
Tom Lagos| brown m
q)kt~ku
1b
q)0!kt
name city eye sex
--------------------
Tom NYC green m
Jo LA blue f
Tom Lagos brown m
Dict is a uniform function on its right domain.
Errors¶
error | cause |
---|---|
length | x and y are not same-length lists |
length | x is not in 1_ til count y |
type | y is not a simple table |
key
,
value
Dictionaries & tables
Q for Mortals
ยง5 Dictionaries