MathGroup Archive 2011

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

Search the Archive

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

?





  • Prev by Date: Re: Pattern matching in lists
  • Next by Date: Re: Read last expression in a file?
  • Previous by thread: Pattern matching in lists
  • Next by thread: Re: Pattern matching in lists