# How do I find the number of ordered group possible as in a sublist from a super list in python?

Suppose I have a smaller list `A = [1,2,3]`

and larger list `B = [1,2,3,1,1,2,2,3,2,3]`

.

**B** has no other elements except **A**'s but elements order is not maintained.

I want to find how many times **A** appears in **B** preserving **A**'s order. For this example **A** appears 3 times in **B**. I could solve this for two elements, like `[1,2]`

comes 2 times in `[1,1,2,2,1,1]`

. In other words, I want to find how many ordered group such **A** is possible from the larger list as **B**.

Rubel Ahmed ask on

## 2 Answers How do I find the number of ordered group possible as in a sublist from a super list in python?

From what I understood, you want to count how many times all the elements of

Aare repeated in order inB, even if there are other elements inbetween.If that's the case, you can use:

## Gsk 1 months ago

An efficient approach is to build a dict of queues of indices for each item in

`B`

, then cycle through items in`A`

to look for the next item in the dict whose index is greater than the index of the last found item by keeping dequeueing until such an index is found or break the loop if any queue is exhausted, with each completed cycle incrementing the count by 1:`count`

becomes:## blhsing 1 months ago