DeleteElements[list,{e1,e2,…}]
removes all instances of elements ei from list.
DeleteElements[list,n{e1,e2,…}]
removes up to n instances of each ei from list.
DeleteElements[list,{n1,n2,…}{e1,e2,…}]
removes up to ni instances of ei from list.
DeleteElements
DeleteElements[list,{e1,e2,…}]
removes all instances of elements ei from list.
DeleteElements[list,n{e1,e2,…}]
removes up to n instances of each ei from list.
DeleteElements[list,{n1,n2,…}{e1,e2,…}]
removes up to ni instances of ei from list.
Details
- The object list can have any head, not necessarily List.
- DeleteElements[list,{n1,n2}{e,e}] removes up to n1+n2 instances of e from list.
- DeleteElements[list,{e1,e2,…}] is equivalent to DeleteElements[list,Infinity{e1,e2,…}].
Examples
open all close allBasic Examples (3)
Delete all instances of x and y from a list:
DeleteElements[{2, x, 1, x, a, y, x}, {x, y}]Remove up to two instances of x:
DeleteElements[{2, x, 1, x, a, y, x}, 2 -> {x}]Remove up to one instance of x and up to two instances of y:
DeleteElements[{2, x, 1, x, a, y, x}, {1, 2} -> {x, y}]Properties & Relations (5)
DeleteElements[list,elems] is equivalent to DeleteElements[list,Infinityelems]:
DeleteElements[{1, 2, 2, 3, 3, 4}, {2, 3}]DeleteElements[{1, 2, 2, 3, 3, 4}, Infinity -> {2, 3}]Remove one instance of b and then remove two other instances of b:
DeleteElements[{a, b, a, b, b, b, c}, {1, 2} -> {b, b}]DeleteElements[list,elems] is equivalent to DeleteCases[list,Alternatives@@elems]:
DeleteElements[{b, a, 2, a, 1, 2}, {1, 2, 3}]DeleteCases[{b, a, 2, a, 1, 2}, Alternatives@@{1, 2, 3}]DeleteElements[list,elems] removes elements from list, preserving the order and multiplicity of the other elements:
DeleteElements[{b, a, 2, a, 1, 2}, {1, 2, 3}]Complement[list,elems] does not preserve the order and multiplicity of the other elements:
Complement[{b, a, 2, a, 1, 2}, {1, 2, 3}]SubsetReplace provides an alternative way of deleting a number of copies of an element from a list:
SubsetReplace[{a, b, c, b, d, c, b}, {Repeated[b, {2}]} -> Nothing]DeleteElements[{a, b, c, b, d, c, b}, 2 -> {b}]Related Guides
History
Text
Wolfram Research (2022), DeleteElements, Wolfram Language function, https://reference.wolfram.com/language/ref/DeleteElements.html.
CMS
Wolfram Language. 2022. "DeleteElements." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/DeleteElements.html.
APA
Wolfram Language. (2022). DeleteElements. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/DeleteElements.html
BibTeX
@misc{reference.wolfram_2026_deleteelements, author="Wolfram Research", title="{DeleteElements}", year="2022", howpublished="\url{https://reference.wolfram.com/language/ref/DeleteElements.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_deleteelements, organization={Wolfram Research}, title={DeleteElements}, year={2022}, url={https://reference.wolfram.com/language/ref/DeleteElements.html}, note=[Accessed: 12-June-2026]}