Re: position of sequence of numbers in list
- To: mathgroup at smc.vnet.net
- Subject: [mg107009] Re: [mg106976] position of sequence of numbers in list
- From: DrMajorBob <btreat1 at austin.rr.com>
- Date: Sun, 31 Jan 2010 05:58:47 -0500 (EST)
- References: <201001301212.HAA25132@smc.vnet.net>
- Reply-to: drmajorbob at yahoo.com
I had no idea this would work... but it does.
list = {1, 2, 3, 4, 5};
Position[list, Sequence[3, 4]]
{{3}}
My first thought was
list /. {before___, 3, 4, ___} :> 1 + Length@{before}
3
But the other is far simpler.
Bobby
On Sat, 30 Jan 2010 06:12:04 -0600, JB <jkerrb at gmail.com> wrote:
> Hi,
>
> What is the most efficient way to find the position of the beginning
> of a sequence of numbers from a list?
>
> I found a couple of ways:
>
> find 3,4 in list={1,2,3,4,5};
>
> 1. pos=Intersection[Position[list,3],(Position[list,4])+1]
>
> 2. pos=Position[Partition[list,2,1],{3,4}]
>
> Are there other ways to do this?
> What is the best way when dealing with large lists?
>
> Thanks,
> JB
>
--
DrMajorBob at yahoo.com
- References:
- position of sequence of numbers in list
- From: JB <jkerrb@gmail.com>
- position of sequence of numbers in list