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 Overlaps->All, multiple sublists that match the same pattern are all included. With Overlaps->True, 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:

In[1]:=
Click for copyable input
Out[1]=

Count the number of appearances of a pattern sequence:

In[1]:=
Click for copyable input
Out[1]=

Scope  (4)

Options  (2)

Properties & Relations  (2)

See Also

Count  SequencePosition  SequenceCases  StringCount  PatternSequence

Introduced in 2015
(10.1)