MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: faster sublist checking


Jens-Peer Kuska wrote:

> Hi,
> 
> In[]:=A = {3, 4, 5}; B = {1, 2, 3, 4, 5, 6, 7};
> 
> In[]:=SublistQ[lst_List, {sub__}] := MatchQ[lst, {__, sub, ___}]
> 
> In[]:=SublistQ[B, A]
> Out[]=True

Hi,

what about A = {3, 5} or A = {3, 5, 4},
are they valid sublists (that's not clear from original post)?
If so, I would suggest

  SublistQ[lst_List, sub_List] := Intersection[lst,sub] == Sort[sub]

Best regards,
Marcus

-- 
The lion and the calf shall lie down together
but the calf won't get much sleep. -- W. Allen


  • Prev by Date: Solutions to the Flexural Gravity Dispersion Relation.. help needed
  • Next by Date: RE: Creating combinations from a group of sets
  • Previous by thread: Re: faster sublist checking
  • Next by thread: Re: faster sublist checking