Dictionaries
Lookup By Key
The most fundamental dictionary operation: given a key, retrieve its value.
Single and Multiple Key Lookup
prices:`AAPL`MSFT`GOOG!185.25 410.10 142.80
prices[`MSFT] / 410.1 — index syntax
prices`MSFT / 410.1 — juxtaposition syntax
prices[`AAPL`GOOG] / 185.25 142.8 — multiple keys at onceIndexing with a list of keys returns a list of values in the same order — lookups are naturally vectorised.
Performance: the Unique Attribute
For small dictionaries, lookup speed is rarely a concern. For dictionaries with many thousands or millions of keys, applying the unique attribute (`u#) to the key vector lets q build an internal hash table, turning lookups into roughly constant-time operations instead of a linear search:
syms:`u#`AAPL`MSFT`GOOG`TSLA`NVDA
prices:syms!185.25 410.10 142.80 238.50 875.20This is a standard optimisation for large reference-data dictionaries — symbol lookups, instrument metadata, exchange mappings — where the key set is known to be unique.
Practice Questions
Test your understanding with 2 hands-on questions