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.
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 all close allBasic Examples (2)
Scope (4)
Count sequences of integers in a list:
SeedRandom[1];
list = RandomChoice[Range[10], 10 ^ 7];
SequenceCount[list, Range[6]]Find their positions in the list:
SequencePosition[list, Range[6]]Count sequences of words in a list:
words = ExampleData[{"Text", "OriginOfSpecies"}, "Words"];SequenceCount[words, {"groups", "of", "species"}]Count sequences of elements that match a pattern:
SequenceCount[Range[1000], {_ ? PrimeQ, _, _ ? PrimeQ}]Count all possible overlapping sequences of length 6:
SequenceCount[Range[10], list_ /; Length[list] == 6, Overlaps -> True]SequenceCases[Range[10], list_ /; Length[list] == 6, Overlaps -> True]Options (2)
Overlaps (2)
SequenceCount[{a, b, a, b, a, b, a, b}, {a, b, a, b}, Overlaps -> True]SequenceCount[{a, b, a, b, a, b, a, b}, {a, b, a, b}, Overlaps -> False]Allow overlaps starting at different positions:
SequenceCount[{a, b, c, d}, {__}, Overlaps -> True]SequenceCount[{a, b, c, d}, {__}, Overlaps -> False]SequenceCount[{a, b, c, d}, {__}, Overlaps -> All]Properties & Relations (3)
Count appearances of a sequence:
SequenceCount[{a, b, 1, 2, c, d, 3, 4}, {__Symbol}, Overlaps -> False]Find the position of the sequence:
SequencePosition[{a, b, 1, 2, c, d, 3, 4}, {__Symbol}, Overlaps -> False]SequenceCases[{a, b, 1, 2, c, d, 3, 4}, {__Symbol}, Overlaps -> False]Replace the sequence by an expression:
SequenceReplace[{a, b, 1, 2, c, d, 3, 4}, {__Symbol} -> "X"]For lists of characters, SequenceCount is very similar to StringCount:
text = "For lists of characters SequenceCount is very similar to StringCount:";SequenceCount[Characters[text], Characters["Count"]]StringCount[text, "Count"]SubsetCount matches the elements of the sequence in any order:
SubsetCount[{1, a, 2, 3, a, b, c}, {a, _Integer}]SubsetCases[{1, a, 2, 3, a, b, c}, {a, _Integer}]SequenceCount matches the sequence only in the specified order:
SequenceCount[{1, a, 2, 3, a, b, c}, {a, _Integer}]SequenceCases[{1, a, 2, 3, a, b, c}, {a, _Integer}]History
Text
Wolfram Research (2015), SequenceCount, Wolfram Language function, https://reference.wolfram.com/language/ref/SequenceCount.html.
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
BibTeX
@misc{reference.wolfram_2026_sequencecount, author="Wolfram Research", title="{SequenceCount}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/SequenceCount.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_sequencecount, organization={Wolfram Research}, title={SequenceCount}, year={2015}, url={https://reference.wolfram.com/language/ref/SequenceCount.html}, note=[Accessed: 13-June-2026]}