# Selecting Parts of Expressions with Functions

"Manipulating Elements of Lists" shows how you can pick out elements of lists based on their positions. Often, however, you will need to select elements based not on where they are, but rather on what they are.

Select[list,f] selects elements of list using the function f as a criterion. Select applies f to each element of list in turn, and keeps only those for which the result is True.

This selects the elements of the list for which the pure function yields True, i.e., those numerically greater than 4.
 In[1]:=
 Out[1]=

You can use Select to pick out pieces of any expression, not just elements of a list.

This gives a sum of terms involving x, y, and z.
 In[2]:=
 Out[2]=
You can use Select to pick out only those terms in the sum that do not involve the symbol x.
 In[3]:=
 Out[3]=
 Select[expr,f] select the elements in expr for which the function f gives True Select[expr,f,n] select the first n elements in expr for which the function f gives True

Selecting pieces of expressions.

"Putting Constraints on Patterns" discusses some "predicates" that are often used as criteria in Select.

This gives the first element which satisfies the criterion you specify.
 In[4]:=
 Out[4]=