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

Examples

open allclose all

Basic Examples  (3)

Delete all instances of x and y from a list:

Remove up to two instances of x:

Remove up to one instance of x and up to two instances of y:

Properties & Relations  (5)

DeleteElements[list,elems] is equivalent to DeleteElements[list,Infinityelems]:

Remove one instance of b and then remove two other instances of b:

DeleteElements[list,elems] is equivalent to DeleteCases[list,Alternatives@@elems]:

DeleteElements[list,elems] removes elements from list, preserving the order and multiplicity of the other elements:

Complement[list,elems] does not preserve the order and multiplicity of the other elements:

SubsetReplace provides an alternative way of deleting a number of copies of an element from a list:

Wolfram Research (2022), DeleteElements, Wolfram Language function, https://reference.wolfram.com/language/ref/DeleteElements.html.

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_2023_deleteelements, author="Wolfram Research", title="{DeleteElements}", year="2022", howpublished="\url{https://reference.wolfram.com/language/ref/DeleteElements.html}", note=[Accessed: 19-April-2024 ]}

BibLaTeX

@online{reference.wolfram_2023_deleteelements, organization={Wolfram Research}, title={DeleteElements}, year={2022}, url={https://reference.wolfram.com/language/ref/DeleteElements.html}, note=[Accessed: 19-April-2024 ]}