MathGroup Archive 2005

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

Search the Archive

Re: Extracting information from lists

  • To: mathgroup at
  • Subject: [mg63354] Re: Extracting information from lists
  • From: Bill Rowe <browe51 at>
  • Date: Sat, 24 Dec 2005 16:03:01 -0500 (EST)
  • Sender: owner-wri-mathgroup at

On 12/24/05 at 7:18 AM, mathstutoring at (Tony King)

>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


>I need a function that will return


>corresponding to the runs {1},{1,1},{1,1,1},{1,1,1,1} within list

I am not aware of any built-in function that will do this. But it is fairly easy to create a function to do this, i.e.,

runStart[data_List] := 
              Cases[Split@data, {_, __}][[1,1]]]], 
    #2 - #1 < 2 & ]

Out[14]={3, 6, 10, 16}

The inner most Split groups runs together. Cases is used to select the runs (assumed to be of a single value}. Position finds the first value of the first run found by Cases. The outer most Split groups the positions into sequential blocks. And finally, the first element of each of these groups is the desired data.

  • Prev by Date: Re: Questions regarding MatrixExp, and its usage
  • Next by Date: Re: Pattern matching at bottom depth
  • Previous by thread: Re: Extracting information from lists
  • Next by thread: Re: Extracting information from lists