MEdan
October 12, 2021, 9:53pm
1
I have a basic question:
a['name] vs b[val;'name]
Do I understand the first is a dictionary and I get the value that corresponds to a key “name”? But what data structure is the second? Is that a list? I am reading the code and trying to make sense of what I see.
Hi MEdan,
It depends if your variable is a dictionary or a table as this flips the indexes:
dictionary = d[key;index]
table = t[index;key]
For example:
q)d:name
iq!(Dent
BeeblebroxPrefect;98 42 126) q)d name| Dent Beeblebrox Prefect iq | 98 42 126 q)t:flip d q)t name iq -------------- Dent 98 Beeblebrox 42 Prefect 126 q)d[;2] name|
Prefect iq | 126 q)d[name;]
DentBeeblebrox
Prefect q)d[name;2]
Prefect q)t[2;] name| Prefect iq | 126 q)t[;
name] Dent
BeeblebroxPrefect q)t[2;
name] `Prefect
Passing only the symbol to either dictionary or table will return the associated values key/column:
q)d iq 98 42 126 q)t
iq 98 42 126
Further reading:
Thanks for posting your query on the portal!
Kind regards,
David