Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Split a list into sublists that match the same pattern from an ordered list of patterns
ResourceFunction["SplitByPatterns"][list,{patt1,patt2,…}] splits list into sublists consisting of runs of successive elements that match the same patti. |
Split into runs of either integers or strings:
In[1]:= | ![]() |
Out[1]= | ![]() |
The first pattern that matches an element is used:
In[2]:= | ![]() |
Out[2]= | ![]() |
If the patterns are reversed, the result may differ:
In[3]:= | ![]() |
Out[3]= | ![]() |
SplitByPatterns[list,{patt1,…}] is equivalent to SplitByPatterns[list,{patt1,…,_}]:
In[4]:= | ![]() |
Out[4]= | ![]() |
This work is licensed under a Creative Commons Attribution 4.0 International License