RemoveAllFromList

RemoveAllFromList

RemoveAllFromList[ remove, list ] returns a copy of a list with all occurrences of the given elements removed.

Usages

RemoveAllFromList[ remove, list ]

RemoveAllFromList[ remove, list ] returns a new list with the elements of list, except all elements that also occur in remove. Note that the elements to remove come first and the list second. The order of the remaining elements is kept.

Example in out
All a's and b's are removed. RemoveAllFromList[ {a, b}, {a, b, c, a, d} ] {c, d}
1+x matches x+1. RemoveAllFromList[ {1, x+1}, {1+x, 2, 1, 3} ] {2, 3}
Details
  • Difference with Difference: RemoveAllFromList removes every occurrence, while Difference removes one occurrence for each element: Difference[ {a, b, c, a, d}, {a, b} ] gives {c, a, d}. Note also the reversed order of the arguments.
  • Equal elements: elements are equal if they are the same expression, regardless of the order of terms or factors. Numbers must have the same form: 2.4 does not match 12/5.
  • Empty list: RemoveAllFromList[ {}, {1, 2} ] returns {1, 2}.
Invalid input Result
RemoveAllFromList[ a, {a, b} ] Left unevaluated: both arguments must be lists. Write {a}.

See also: Difference, RemoveI, Unique