MathGroup Archive 2010

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

Search the Archive

Re: Re: position of sequence of numbers in list


Patrick, Bob,

Please educate me if I am misunderstanding, but Position is not SequenceHold
and therefore, your constructs don't seem to work for me. They seem to work
only because you provided length - 2 or length- 3 sequences (try length-4
and I am getting en error for v7), which Position interprets as 2 or 3
additional arguments. Thus,

Position[list, Sequence[11, 12, 13]] is equivalent to

Position[list, 11,12,13], which means:

find position of element <11> in the first 12 levels of expression (<list>),
stopping with at most 13 results. By accident (or luck), this gives correct
result on the toy example that you have. The same situation with Bob's
example Position[list, Sequence[3, 4]].
Or is this an extension of v.7.1, that I am not aware of?

Regards,
Leonid

On Sun, Jan 31, 2010 at 2:55 AM, Patrick Scheibe <
pscheibe at trm.uni-leipzig.de> wrote:

> Hi,
>
> I assume the only thing you miss is how to express a "sequence of
> numbers"? Just use Sequence[] :-)
>
> list=Range[20];
> Position[list, Sequence[11, 12, 13]]
>
> Cheers
> Patrick
>
> On Sat, 2010-01-30 at 07:12 -0500, JB 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
> >
>
>
>


  • Prev by Date: Re: newbe question about Sting Comparison
  • Next by Date: Re: Re: position of sequence of numbers in list
  • Previous by thread: Re: position of sequence of numbers in list
  • Next by thread: Re: position of sequence of numbers in list