Skip to content

DeleteCases ​

list with every top-level element matching pattern removed.

✓ checked against that system · ! checked, with disagreements (hover a chip)Wolfram LanguageDeleteCases✓
DeleteCases(list, pattern)the elements of list that do NOT match pattern
Typed signatures
TypePackageApplies
(any, any) -> anycombinatoricsalways

Domain: Collections

Details
  • Top level only — Wolfram's optional levelspec/n (search below the top, cap how many to delete) aren't implemented.
  • Built on the same match primitive as MatchQ and FreeQ, so it shares their wildcard grammar and their limits.
  • A string-literal pattern inherits a compute-engine quirk: two EQUAL string literals don't count as a match (MatchQ already answers False for it), so DeleteCases won't remove them either — not something patched around here.

Examples

Basic #
live ↗
InDeleteCases([1,2,3,2,4],2)\mathrm{DeleteCases}(\bigl\lbrack1, 2, 3, 2, 4\bigr\rbrack, 2)Out[1,3,4]\bigl\lbrack1, 3, 4\bigr\rbrack
Scope #
live ↗
InDeleteCases([x,y,z],_a⁡)\mathrm{DeleteCases}(\bigl\lbrack x, y, z\bigr\rbrack, \operatorname{\_a})Out[]\bigl\lbrack\bigr\rbrack
About
Examples2
Checked againstWolfram Language 1 agree
CrosswalkWolfram Language

See also: MatchQ, FreeQ, Pick