DeleteAdjacentDuplicates
DeleteAdjacentDuplicates[list]
deletes all duplicates in runs of identical elements in list.
DeleteAdjacentDuplicates[list,test]
applies test to pairs of consecutive elements to determine whether they should be considered duplicates.
Details
- DeleteAdjacentDuplicates[list] deletes all but the first occurrence of each element that appears in a run of identical elements in list.
- DeleteAdjacentDuplicates also works on associations.
- DeleteAdjacentDuplicates never reorders elements, but only removes them.
- DeleteAdjacentDuplicates[list] is equivalent to DeleteAdjacentDuplicates[list,SameQ].
Examples
open allclose allBasic Examples (3)
Delete adjacent duplicated elements:
Delete adjacent elements that coincide under Equal:
Delete elements whose values duplicate those just before them in the association:
Scope (2)
Delete elements unless they are larger than the preceding ones:
In DeleteAdjacentDuplicates[list], list may be any nonatomic expression:
Properties & Relations (2)
DeleteAdjacentDuplicates is similar to taking the first of each item from Split:
Delete sublists that have the same total:
The equivalent operation can be achieved using SplitBy as well:
Text
Wolfram Research (2022), DeleteAdjacentDuplicates, Wolfram Language function, https://reference.wolfram.com/language/ref/DeleteAdjacentDuplicates.html.
CMS
Wolfram Language. 2022. "DeleteAdjacentDuplicates." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/DeleteAdjacentDuplicates.html.
APA
Wolfram Language. (2022). DeleteAdjacentDuplicates. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/DeleteAdjacentDuplicates.html