SplitBy

SplitBy[list,f]

splits list into sublists consisting of runs of successive elements that give the same value when f is applied.

SplitBy[list,{f1,f2,}]

recursively splits list into sublists by testing elements successively with each of the fi.

Details

  • SplitBy[list,] splits but does not rearrange list.
  • SplitBy performs comparisons only on adjacent pairs of elements.
  • SplitBy[list] is equivalent to SplitBy[list,Identity], which is also equivalent to Split[list].
  • SplitBy[list,{f1,f2}] is equivalent to Map[SplitBy[#,f2]&,SplitBy[list,f1]].

Examples

open allclose all

Basic Examples  (3)

Split into runs of numbers with identical integer part:

Split into runs of triples with identical first component:

Split first by their first component and then by their second:

Split dates into runs with identical year:

Applications  (1)

Split by sign:

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

Text

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

CMS

Wolfram Language. 2008. "SplitBy." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/SplitBy.html.

APA

Wolfram Language. (2008). SplitBy. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/SplitBy.html

BibTeX

@misc{reference.wolfram_2024_splitby, author="Wolfram Research", title="{SplitBy}", year="2008", howpublished="\url{https://reference.wolfram.com/language/ref/SplitBy.html}", note=[Accessed: 21-December-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_splitby, organization={Wolfram Research}, title={SplitBy}, year={2008}, url={https://reference.wolfram.com/language/ref/SplitBy.html}, note=[Accessed: 21-December-2024 ]}