Mathematica 9 is now available
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.
Mathematica > Core Language > Expressions > Parts of Expressions > DeleteCases >

DeleteCases

DeleteCases
removes all elements of expr that match pattern.
DeleteCases
removes all parts of expr on levels specified by levelspec that match pattern.
DeleteCases
removes the first n parts of expr that match pattern.
  • With the option Heads->True, you can delete heads with DeleteCases. Deleting the head of a particular element in an expression is equivalent to applying FlattenAt to the expression at that point.
nlevels through n
Infinitylevels through Infinity
{n}level n only
{n1,n2}levels through
  • 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 consists of numbers, symbols, and other objects that do not have subparts.
  • Level corresponds to the whole expression.
  • DeleteCases traverses the parts of expr in a depth-first order, with leaves visited before roots.
Delete cases that match integers:
Delete cases that match integers:
In[1]:=
Click for copyable input
Out[1]=
Deleting the head effectively flattens:
New in 2 | Last modified in 4.1
Ask a question about this page  |  Suggest an improvement  |  Leave a message for the team
Format:   HTML  |  CDF