Wolfram Computation Meets Knowledge

ElementQ

Contributed by: Taliesin Beynon

Test if an element is contained in a list.

ResourceFunction["ElementQ"][elem,list]

gives True if the value elem is present in list.

ResourceFunction["ElementQ"][list]

is the operator form of ElementQ.

Details and Options

elem must be at level 1 in the list.
list can have any head, not necessarily List.
elem can be any expression.
ResourceFunction["ElementQ"] does not use patterns or functions for testing.

Examples

Basic Examples

Basic usage:

In[1]:=
ResourceFunction["ElementQ"][1, Range[5]]
Out[1]=

Operator form:

In[2]:=
ResourceFunction["ElementQ"][{1, 2, 3, 4, 5}][1]
Out[2]=

Test strings:

In[3]:=
ResourceFunction["ElementQ"]["Æ", CharacterRange[150, 200]]
Out[3]=

Test algebraic expressions:

In[4]:=
ResourceFunction["ElementQ"][x^2, Table[x^n, {n, 6}]]
Out[4]=

Head can be any other than List:

In[5]:=
ResourceFunction["ElementQ"][b, f[a, b, c]]
Out[5]=

Properties and Relations

ElementQ[elem,list] is equivalent to MemberQ[list,elem]:

In[6]:=
MemberQ[Range[5], 1]
Out[6]=

Possible Issues

ElementQ test only elements at level 1:

In[7]:=
ResourceFunction["ElementQ"][2, {1, {2}, 3, 4, 5}]
Out[7]=

Resource History