Re: Pattern matching in lists

*To*: mathgroup at smc.vnet.net*Subject*: [mg116118] Re: Pattern matching in lists*From*: Bob Hanlon <hanlonr at cox.net>*Date*: Thu, 3 Feb 2011 05:26:06 -0500 (EST)

dataT = {1, 3, 2, 6, 5, 1, 4, 6, 3, 9}; dataF = {1, 3, 2, 6, 5, 1, 3, 6, 3, 9}; target = {1, 4, 6}; MemberQ[Partition[#, 3, 1], target] & /@ {dataT, dataF} {True, False} # /. {{s___, Sequence @@ target, f___} -> True, {__} -> False} & /@ {dataT, dataF} {True, False} Bob Hanlon ---- "Harvey P. Dale" <hpd1 at nyu.edu> wrote: ============= MemberQ easily tests whether a single integer appears in a list of integers. Suppose, however, that I want to test not for a single integer but for two or more consecutive integers, e.g., to see whether {1,4,6} is a member of {1,3,2,6,5,1,4,6,3,9}. I can do this by converting both lists into strings and then using string-matching functions, but is there some way of doing it directly without that conversion? Thanks.