MathGroup Archive 2005

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

Search the Archive

Re: Extracting information from lists

  • To: mathgroup at smc.vnet.net
  • Subject: [mg63348] Re: [mg63323] Extracting information from lists
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Sat, 24 Dec 2005 16:02:57 -0500 (EST)
  • Reply-to: hanlonr at cox.net
  • Sender: owner-wri-mathgroup at wolfram.com

runPos[lst_List, elem_]:=Module[{rn=False},
      Flatten@Position[
          If[#==elem,If[rn,0,rn=True;1],rn=False;0]&
            /@lst,1]];

lst={7,9,1,6,8,1,1,6,5,1,1,1,8,7,6,1,1,1,1,7};

runPos[lst,1]

{3,6,10,16}


Bob Hanlon

> 
> From: "Tony King" <mathstutoring at ntlworld.com>
To: mathgroup at smc.vnet.net
> Date: 2005/12/24 Sat AM 07:18:50 EST
> Subject: [mg63348] [mg63323] Extracting information from lists
> 
> Does anyone know of a function that will allow me to extract the positions 
> of the first elements of runs of similar elements within a list. For 
> example, suppose that
> 
> list={7,9,1,6,8,1,1,6,5,1,1,1,8,7,6,1,1,1,1,7}
> 
> I need a function that will return
> 
> {3,6,10,16}
> 
> corresponding to the runs {1},{1,1},{1,1,1},{1,1,1,1} within list
> 
> Many thanks
> 
> Tony 
> 
> 


  • Prev by Date: Re: Pattern matching at bottom depth
  • Next by Date: Re: ExpToTrig with Real Numbers
  • Previous by thread: Re: Extracting information from lists
  • Next by thread: Re: Extracting information from lists