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

Level

Level[expr, levelspec]
gives a list of all subexpressions of expr on levels specified by levelspec.
Level[expr, levelspec, f]
applies f to the sequence of subexpressions.
  • Level uses standard level specifications:
nlevels 1 through n
Infinitylevels 1 through Infinity
{n}level n only
{n1,n2}levels n1 through n2
  • Level[expr, {-1}] gives a list of all "atomic" objects in expr.
  • A positive level n consists of all parts of expr specified by n indices.
  • A negative level -n consists of all parts of expr with depth n.
  • 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.
New in 1