Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

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

Search the Archive

Re: finding the position of a pattern in list

  • To: mathgroup at
  • Subject: [mg64638] Re: finding the position of a pattern in list
  • From: Bill Rowe <readnewsciv at>
  • Date: Fri, 24 Feb 2006 00:19:27 -0500 (EST)
  • Sender: owner-wri-mathgroup at

On 2/23/06 at 12:34 AM, contactmagang at (Gang Ma) wrote:

>Hi, I am working on a program to do the following: My data is a
>list of 0 and 1. For example, {0,0,1,1,1,0,0,1,1,1,0}. I want to
>find the positions of all the pattern of {0,1}.  In my previous
>example, the first {0,1} is at 2 and and the second {0,1} appears
>at 7. I can write a loop to do this, but I have several thousands
>such lists, the computation will be time consuming using loop.

>My question is whether it is possible to use the pattern match to
>do this quickly.  If not for the list, do I need to convert the
>list to string then use some pattern match for string?  Thank you
>very much.

A simple way to accomplish this without a loop or string conversion is using Position with Partition, i.e.


{{2}, {7}}

And you could make this a bit more general purpose with:



{{2}, {7}}
To reply via email subtract one hundred and four

  • Prev by Date: Re: Matrix multiplication problem fixed via dot operation.
  • Next by Date: Re: Code to translate to negative base...
  • Previous by thread: Re: finding the position of a pattern in list
  • Next by thread: Re: Re: finding the position of a pattern in list