Re: Pattern matching in lists
- To: mathgroup at smc.vnet.net
- Subject: [mg116117] Re: Pattern matching in lists
- From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
- Date: Wed, 2 Feb 2011 07:05:23 -0500 (EST)
- References: <201102021107.GAA24311@smc.vnet.net>
On 2 Feb 2011, at 20:07, Harvey P. Dale 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. > > Harvey > How about: MatchQ[{1, 3, 2, 6, 5, 1, 4, 6, 3, 9}, Flatten[{BlankNullSequence[], {1, 4, 6}, BlankNullSequence[]}]] True ?
- References:
- Pattern matching in lists
- From: "Harvey P. Dale" <hpd1@nyu.edu>
- Pattern matching in lists