I have a database for example datatest
(Length[datatest]=10
) :
datatest={
{52, 2, 5, 1, 5, 1, 15, 2, 13, 2, 2},
{1, 1, 2, 1, 1, 2, 2, 1, 2, 2, 1},
{2, 6, 4, 3, 8, 4, 2, 9, 4, 6, 5},
{0, 0, 0, 0, 1, 2, 2, 3, 2, 0, 83},
{1, 6, 4, 6, 2, 12, 4, 8, 2, 12, 5},
{1, 1, 2, 2, 3, 3, 4, 41, 11, 12, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{15, 22, 40, 43, 49, 52, 58, 14, 120, 150, 305},
{32, 38, 46, 54, 64, 76, 89, 104, 122, 585, 760}
}
Now I have a list for instance: checklist={40, 43, 49, 52}
If I want to know whether the checklist
is in the datatest
, the easy way to do is as following:
For[iii= 1, iii<= Length[datatest], iii++,
exist = SequenceCount[datatest[[iii]], checklist];
If[exist!=0,
... (*here i ignore the code, just for dealing with the data*)
Break[],
... (*here i ignore the code, just for dealing with the data*)
];
];
I will search datatest
many time, so when the datatest
is very large (Length[datatest]
is large), it will take a lot of time with the above for-loop method . So I wonder whether there is a fast way to do such thing?
I think the question can be written as How to check whether a sublist exist in a large nested lists in a fast way?
Thank you very much!