When looking up if a simple dictionary includes a certain value you can use a technique known as Reverse Lookup using the ? (find) operator. See example 1. This will return the key that particular value is stored under.
Ex 1:
q)d: 1 2 3 4!5 6 7 8
q)d
1| 5
2| 6
3| 7
4| 8
q)d?5
1
q)d?6
2
When using Reverse Lookup in a non-simple dictionary the find (?) operator won’t work without the entire list of values for a particular key. See example 2.
Ex 2:
q)d:(ab; cde; enlist f)!10 20 30
q)d?20
cd`e
q)d:ab`c!(10 20; 30 40 50; enlist 60)
q)d `b
30 40 50
q)d?30 40 50
`b
q)d?40
`
In a nested dictionary we can use a mixture of the in operator and the each both iterator to determine the keys and values that contain a boolean true. See example 3.
As I said, today is my first day with kdb + e q. Many news.
With your explanation and Connor’s explanation, I started to understand better how the q language works.
A big news for me:
q code is has no order of precedence, it is interpreted from right to left.
Note:
q) 5 in`d
q) d where 1 = 5 in’d
presented error.
Look how it worked for me:
q) 5 in /: d
q) where 5 in: / d
q) d where 5 in: / d
Thank you very much for the tips and suggestions.
A big hug to everyone!
Em segunda-feira, 12 de outubro de 2020 às 12:40:28 UTC-3, caitlin...@aquaq.co.uk escreveu:
Hi!
When looking up if a simple dictionary includes a certain value you can use a technique known as Reverse Lookup using the ? (find) operator. See example 1. This will return the key that particular value is stored under.
Ex 1:
q)d: 1 2 3 4!5 6 7 8
q)d
1| 5
2| 6
3| 7
4| 8
q)d?5
1
q)d?6
2
When using Reverse Lookup in a non-simple dictionary the find (?) operator won’t work without the entire list of values for a particular key. See example 2.
Ex 2:
q)d:(ab; cde; enlist f)!10 20 30
q)d?20
cd`e
q)d:ab`c!(10 20; 30 40 50; enlist 60)
q)d `b
30 40 50
q)d?30 40 50
`b
q)d?40
`
In a nested dictionary we can use a mixture of the in operator and the each both iterator to determine the keys and values that contain a boolean true. See example 3.
Much could and should be done to improve the site as a resource for solo study. However, when people study alone it is hard for us to see where difficulties need removing.
Any comments or observations as you learn would be most welcome! (This goes for everyone in this group.)