Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

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

Search the Archive

Re: faster sublist checking

  • To: mathgroup at smc.vnet.net
  • Subject: [mg48700] Re: faster sublist checking
  • From: Marcus Stollsteimer <marcus314 at yahoo.com>
  • Date: Fri, 11 Jun 2004 03:52:24 -0400 (EDT)
  • References: <ca6hlt$fgj$1@smc.vnet.net> <ca922l$7p$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

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