! Dict¶
Make a dictionary or keyed table; remove a key from a table
x!y ![x;y]
Where
xandyare same-length lists, returns a dictionary in whichxis the key andyis the valueyis a simple table andxis a member of1_til count y, returns a keyed table with the firstxcolumns as its keyyis a table andxis 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