Function Repository Resource:

# ContainsOrderedItemsQ

Test whether a list contains a subsequence without requiring the subsequence to be in a single sequence

Contributed by: Jon McLoone, Daniel Robinson
 ResourceFunction["ContainsOrderedItemsQ"][list1,list2] returns True if the elements of list2 all occur in the same order within list1, and False otherwise.

## Examples

### Basic Examples (2)

The numbers 1, 4 and 2 occur in this order in the sequence 1, 2, 3, 4, 3, 2, 1:

 In[1]:=
 Out[1]=

The numbers 2, 1, 2 appear in the same sequence but not in this order:

 In[2]:=
 Out[2]=

Check a list of digits for a range of sequential integers:

 In[3]:=
 Out[3]=
 In[4]:=
 Out[4]=

### Scope (1)

Strings are automatically converted to lists of characters:

 In[5]:=
 Out[5]=

### Properties and Relations (2)

ContainsOrderedItemsQ is different from SequenceCount and related functions because it allows the subsequence to be interrupted:

 In[6]:=
 Out[6]=
 In[7]:=
 Out[7]=

SequenceCount, on the other hand, requires the sequence to be together:

 In[8]:=
 Out[8]=
 In[9]:=
 Out[9]=

Jon McLoone

## Requirements

Wolfram Language 13.0 (December 2021) or above

## Version History

• 1.0.1 – 13 March 2024
• 1.0.0 – 13 March 2023