Level
Details and Options
- Level uses standard level specifications:
-
n levels 1 through 
Infinity levels 1 through Infinity {n} level
only{n1,n2} levels
through 
- Level[expr,{-1}] 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.
Examples
open all close allBasic Examples (6)
Level[a + f[x, y ^ n], {-1}]Give all parts down to level 2:
Level[a + f[x, y ^ n], 2]Give all parts at levels 0 through infinity:
Level[a + f[x, y ^ n], {0, Infinity}]Get all leaves from an Association:
Level[<|1 -> a, 2 -> b|>, -1]Values in an Association are at the first level:
Level[<|1 -> a, 2 -> b|>, {1}]Give elements from nested associations:
Level[<|1 -> <|a -> b, c -> d|>|>, {2}]Level[<|1 -> <|a -> b, c -> d|>|>, {1, 2}]Generalizations & Extensions (5)
Down successive numbers of levels:
Level[{{{{a}}}}, 1]Level[{{{{a}}}}, 2]Level[{{{{a}}}}, 3]Level[{{{{a}}}}, 4]Level[{{{{a}}}}, 5]Level[{{{{a}}}}, -1]Level[{{{{a}}}}, -2]Level[{{{{a}}}}, -3]Level[{{{{a}}}}, -4]Level[{{{{a}}}}, -5]Level[{{{{a}}}}, {2, 3}]Level[{{{{a}}}}, {0, -1}]Use different heads at each level:
Level[h0[h1[h2[h3[a]]]], {0, -1}]Level[{{{{a}}}}, 3, Heads -> True]Level[x ^ 2 + y ^ 3, 3, Heads -> True]Applications (1)
Properties & Relations (2)
Level always lists parts in the lexicographic order of their indices:
Array[a, {2, 2, 2}]Level[%, {3}]Depth[expr] is the smallest positive-level k for which Level[expr,{k}] returns an empty list:
expr = a + f[x, y ^ n];Table[Level[expr, {k}], {k, 0, Depth[expr]}]Possible Issues (1)
Level by default starts at level 1, so it does not include the whole expression:
Level[h1[h2[h3[x]]], -1]Level[h1[h2[h3[x]]], {0, -1}]Tech Notes
Related Guides
History
Introduced in 1988 (1.0)
Text
Wolfram Research (1988), Level, Wolfram Language function, https://reference.wolfram.com/language/ref/Level.html.
CMS
Wolfram Language. 1988. "Level." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/Level.html.
APA
Wolfram Language. (1988). Level. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Level.html
BibTeX
@misc{reference.wolfram_2026_level, author="Wolfram Research", title="{Level}", year="1988", howpublished="\url{https://reference.wolfram.com/language/ref/Level.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_level, organization={Wolfram Research}, title={Level}, year={1988}, url={https://reference.wolfram.com/language/ref/Level.html}, note=[Accessed: 13-June-2026]}