# Find one list inside another.

**URL:** <https://forum.kx.com/t/find-one-list-inside-another/11001>\
**Category:** Community Support\
**Tags:** kdb-and-q\
**Created:** [April 28, 2016, 4:35pm UTC](https://forum.kx.com/t/find-one-list-inside-another/11001 "2016-04-28T16:35:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Krishna1](https://avatars.discourse-cdn.com/v4/letter/k/71e660/32.png) [@Krishna1](https://forum.kx.com/u/Krishna1)\
**Post date:** [April 28, 2016, 4:35pm UTC](https://forum.kx.com/t/find-one-list-inside-another/11001/1 "2016-04-28T16:35:00Z")

</div>

I’m doing the following:

g: (1;(1 2)

n: (1 2 2)

then,&nbsp;

g?n - based on the page&nbsp;http://code.kx.com/wiki/Reference/QuestionSymbol#find - I seem to be doing it correct. However, I get the answer as ,1.&nbsp;

Why is the find reporting “n” as found inside “g”?&nbsp; And how do I fix it?&nbsp;

Thanks,&nbsp;

Kumar

---

<div class="post-metadata">

**Author:** ![mkrmkr1](https://avatars.discourse-cdn.com/v4/letter/m/ba9def/32.png) [@mkrmkr1](https://forum.kx.com/u/mkrmkr1)\
**Post date:** [April 28, 2016, 6:47pm UTC](https://forum.kx.com/t/find-one-list-inside-another/11001/2 "2016-04-28T18:47:00Z")

</div>

find (?) is atomic right, meaning that it treats each element of a list on the right hand side separately.  
i don’t know what you’re actually doing but i suspect it’s not exactly what you said.  
console snapshots are always best for questions like these.

q)g:(1;(1 2)) /note your example is missing a )  
q)n:(1 2 2) /note the () are redundant here  
q)g?n  
0 2 2  
q)/first element of n, 1, is found in the 0th position of g  
q)/second and third elements of n, 2 2, are not found and so count[g] is returned for each of them  
q)

hope this helps,  
mike

---

<div class="post-metadata">

**Author:** ![Krishna1](https://avatars.discourse-cdn.com/v4/letter/k/71e660/32.png) [@Krishna1](https://forum.kx.com/u/Krishna1)\
**Post date:** [April 29, 2016, 2:36am UTC](https://forum.kx.com/t/find-one-list-inside-another/11001/3 "2016-04-29T02:36:00Z")

</div>

Thanks a lot, Mike. I’m now using the code :

q)g &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;

1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;

1 2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;

q)nxt &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;

1 2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;

q){where x~:y}[g;nxt]&nbsp;

`long$()

q)

I check for empty list return(i.e - `long$()) by doing a count of the return value.&nbsp;

Kumar&nbsp;

---

<div class="post-metadata">

**Author:** ![Krishna1](https://avatars.discourse-cdn.com/v4/letter/k/71e660/32.png) [@Krishna1](https://forum.kx.com/u/Krishna1)\
**Post date:** [April 29, 2016, 4:06am UTC](https://forum.kx.com/t/find-one-list-inside-another/11001/4 "2016-04-29T04:06:00Z")

</div>

Sorry, nxt was 1 2 2 in the above example.&nbsp;

q)g &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;

1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;

1 2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;

q)nxt &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;

1 2 &nbsp;2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;

q){where x~:y}[g;nxt]&nbsp;

`long$()

I check for empty list return(i.e - `long$()) by doing a count of the return value.&nbsp;

Kumar
