SequenceCount

SequenceCount[list,sub]

gives a count of the number of times sub appears as a sublist of list.

SequenceCount[list,patt]

gives the number of sublists in list that match the general sequence pattern patt.

Details and Options

  • In SequenceCount[list,patt], patt can be an expression with head List that includes pattern constructs such as PatternSequence, Repeated (..), Blank (_), and BlankSequence (__).
  • The pattern patt can also be a pattern that matches a list, though does not itself have head List.
  • With the default option setting OverlapsFalse, SequenceCount includes only sublists that do not overlap. With the setting OverlapsTrue, it includes sublists that overlap.
  • With OverlapsAll, multiple sublists that match the same pattern are all included. With OverlapsTrue, only the first such matching sublist at a given position is included.

Examples

open allclose all

Basic Examples  (2)

Count the number of appearances of a sublist:

Count the number of appearances of a pattern sequence:

Scope  (4)

Count sequences of integers in a list:

Find their positions in the list:

Count sequences of words in a list:

Count sequences of elements that match a pattern:

Count all possible overlapping sequences of length 6:

These are the possibilities:

Options  (2)

Overlaps  (2)

Allow overlaps:

Allow no overlaps:

Allow overlaps starting at different positions:

Allow no overlaps:

Allow all overlaps:

Properties & Relations  (3)

Count appearances of a sequence:

Find the position of the sequence:

Find the actual sequence:

Replace the sequence by an expression:

For lists of characters, SequenceCount is very similar to StringCount:

SubsetCount matches the elements of the sequence in any order:

SequenceCount matches the sequence only in the specified order:

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

Text

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

BibTeX

@misc{reference.wolfram_2020_sequencecount, author="Wolfram Research", title="{SequenceCount}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/SequenceCount.html}", note=[Accessed: 27-February-2021 ]}

BibLaTeX

@online{reference.wolfram_2020_sequencecount, organization={Wolfram Research}, title={SequenceCount}, year={2015}, url={https://reference.wolfram.com/language/ref/SequenceCount.html}, note=[Accessed: 27-February-2021 ]}

CMS

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

APA

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