This is documentation for Mathematica 8, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)

Level

Level
gives a list of all subexpressions of expr on levels specified by levelspec.
Level
applies f to the sequence of subexpressions.
  • Level uses standard level specifications:
nlevels 1 through
Infinitylevels 1 through Infinity
{n}level only
{n1,n2}levels through
  • Level gives a list of all "atomic" objects in expr.
  • A positive level consists of all parts of expr specified by indices.
  • A negative level consists of all parts of expr with depth .
  • Level 0 corresponds to the whole expression.
  • With the option setting Heads->True, Level includes heads of expressions, and their parts.
  • Level traverses expressions in depth-first order, so that the subexpressions in the final list are ordered lexicographically by their indices.
Give all parts at level -1:
Give all parts down to level 2:
Give all parts at levels 0 through infinity:
Give all parts at level -1:
In[1]:=
Click for copyable input
Out[1]=
 
Give all parts down to level 2:
In[1]:=
Click for copyable input
Out[1]=
 
Give all parts at levels 0 through infinity:
In[1]:=
Click for copyable input
Out[1]=
Down successive numbers of levels:
Negative levels:
Ranges of levels:
Use different heads at each level:
Including heads:
Find the leaf elements in an expression:
Include heads:
Find unique leaf expressions:
Level always lists parts in the lexicographic order of their indices:
Level by default starts at level 1, so it does not include the whole expression:
New in 1