SequenceSplit

SequenceSplit[list,patt]

splits list into sublists separated by sequences that match the sequence pattern patt.

SequenceSplit[list,pattrhs]

inserts rhs at the position of each matched sequence.

SequenceSplit[list,{patt1rhs1,}]

inserts rhsi at the position of each patti.

SequenceSplit[list,patt,n]

splits into at most n sublists.

Details

  • SequenceSplit[list,patt] by default gives the list of sublists of list that occur between sequences defined by patt; it does not include the sequences themselves.
  • SequenceSplit[list,{patt1rhs1,,patta,}] includes rhsi at the position of sequences matching patt1 but omits sequences matching patta.

Examples

open allclose all

Basic Examples  (3)

Split at sequences that match a pattern:

Insert an expression at the position of the matched sequences:

Split into at most 2 sublists:

Scope  (6)

Use a pattern to split the original list:

Use a rule to replace the matched sequences:

Split the original list at sequences that match any of the patterns:

Use a list of rules to replace the matched sequences:

Use rules and patterns:

Split into at most 2 sublists:

Applications  (1)

Find the most frequent length for a run of consecutive non-prime numbers:

Properties & Relations  (8)

Insert a list of elements at the position of the matched sequence:

Use Sequence instead of List to splice the elements in the output list:

Rules are tried in the given order:

A list of sublists is considered as a single sequence pattern:

Use Alternatives to split at any of the sequence subpatterns:

The third argument of SequenceSplit is the count of sublists not considering insertions:

Split a list into sublists delimited by sequences that match a pattern:

Replace a sequence by an expression:

Find the position of the sequence:

Find the actual sequence:

Count the number of cases:

Split at any sequence of integers:

Use SequenceCases instead:

For lists of characters, SequenceSplit is similar to StringSplit:

Split by parity:

Compare with SplitBy:

Introduced in 2018
 (11.3)