Assuming you don't need to arrange the elements, here is one way:
In[20]:= Complement[Flatten[nList],lList]
EDIT
If order matters, then this is one way:
In[29]:= And@ @(MatchQ[lList,{___,PatternSequence[
For a large number of subscriptions, this can be faster:
In[34]:= Union[ReplaceList[lList, {___,x: Alternatives@ @( PatternSequence@ @@nList),___}:>{x}]]===Union[nList] Out[34]= False
This works as follows: ReplaceList is a very good, but often ignored command that returns a list of all possible expressions that can be obtained using a template that tries to apply the rules in every possible way to the expression. This contrasts with the way the pickup template usually works, where it stops at the first successful match. PatternSequence is a relatively new addition to the Mathematica template language, which allows us to give an identity to a given sequence of expressions, considering it as a pattern. This allowed us to build an alternative template, so the resulting template says: the sequence of any sublist anywhere in the main list is collected and returned back to the brackets of the list, forming the sublist back. We get as many newly formed subscriptions as possible, as there are sequences of source sublists in a larger list. If all sublists are present, then Union in the resulting list should be the same as Union original list of sublists.
Here are the tests (I took a list of integers and overlapping signatures created by Partition ):
In[39]:= tst = Range[1000]; In[41]:= sub = Partition[tst, 2, 1]; In[43]:= And @@ (MatchQ[tst, {___, PatternSequence[
Itβs clear that the reason the second method works faster is because it does its work in a single run through the list (internally using the ReplaceList ), while the first solution explicitly iterates through the large list for each subscription.
EDIT 2 - Performance
If performance is really a problem, the following code is even faster:
And @@ (With[{part = Partition[lList, Length[
For example, in our tests:
In[54]:= And@ @(With[{part = Partition[tst,Length[
EDIT 3
At the suggestion of @ Mr.Wizard, the following performance improvement can be made:
Scan[ If[With[{part = Partition[lList, Length[
Here, as soon as we get a negative answer from subscriptions for a given length, sublists of other lengths will not be checked, since we already know that the answer is negative ( False ). If Scan completes without Return , it will return Null , which means that lList contains all the signatures in nList .