# `in`

_Whether `x` is an item of `y`_
```syntax
x in y    in[x;y]
```

Where `y` is

- an _atom or vector_ of the same type as `x`, returns whether atoms of `x` are items of `y`
- a _list_, returns as a boolean atom whether `x` is an item of `y`

Where `y` is an atom or vector, comparison is [left-atomic](glossary.md#left-atomic-function).
```q
q)"x" in "a"                                    / atom in atom
0b
q)"x" in "acdexyz"                              / atom in vector
1b
q)"wx" in "acdexyz"                             / vector in vector
01b
q)("abc";("def";"ghi");"jkl")in "bed"           / list in vector
010b
(110b;000b)
000b
```

Where `y` is a list, there is no iteration through `x`.
```q
q)"wx" in ("acdexyz";"abcd";"wx")               / vector in list
1b
q)("ab";"cd") in (("ab";"cd");0 1 2)            / list in list
1b
q)any ("ab";"cd") ~/: (("ab";"cd");0 1 2)
1b
```

Further examples:
```q
q)1 3 7 6 4 in 5 4 1 6        / which of x are in y
10011b
q)1 2 in (1 2;9)              / 1 2 is an item of y
1b
q)1 2 in ((1 2;3 4);9)        / 1 2 is not an item of y
0b
q)(1 2;3 4) in ((1 2;3 4);9)  / x is an item of y
1b
```

`in` uses [Find](find.md) to search for `x` in `y`.

`in` is a [multithreaded primitive](mt-primitives.md).

## Queries

`in` is often used with [`select`](select.md).
```q
q)p:([p:`p1`p2`p3`p4`p5]name:`nut`bolt`screw`screw`cam;city:`london`paris`rome`london`paris)
q)select from p where city in `paris`rome
p | name  city
--| -----------
p2| bolt  paris
p3| screw rome
p5| cam   paris
```

## Mixed argument types

Optimized support for an atom or one-item list `y` allows a wider mix of input types.
```q
q)1 2. in 2
01b
q)1 2. in 1#2
01b
q)1 2. in 0#2
'type
  [0]  1 2. in 0#2
            ^
q)1 2. in 2#2
'type
  [0]  1 2. in 2#2
            ^
```

This optimization applies only when `y` is an atom or a one-item list.

> **Danger — Don’t rely on mixed argument types. This behavior might be removed in a future release.**
>
>
## Mixed argument ranks

> **Warning — Results for mixed-rank arguments can be unexpected.**
>
>
```q
q)3 in (1 2;3)
0b
q)3 in (3;1 2)
1b
```

Where the first item of a general list `y` is an atom, `in` searches `y` for each item of `x`, rather than for `x` as a whole:
```q
q)1 2 in (1 2;9)
1b
q)1 2 in (9;1 2)
00b
```

Instead, use [Match](match.md):
```q
q)any ` ~/: (1 2;`)
1b
q)any 1 2 ~/: (9;1 2)
1b
```

----

[`except`](except.md),
[`inter`](inter.md),
[`within`](within.md),
[`union`](union.md)


[Search](by-topic.md#search)
