Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

Re: Extracting information from lists

  • To: mathgroup at smc.vnet.net
  • Subject: [mg63343] Re: [mg63323] Extracting information from lists
  • From: "David Park" <djmp at earthlink.net>
  • Date: Sat, 24 Dec 2005 16:02:53 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Tony,

Here is one method, but there may be shorter methods. (I changed the first 6
in your list to 1 to correspond with your result.)

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

dupstartpositions[list_?VectorQ] :=
  Module[{lengths, startpositions},
    lengths = Length /@ Split[list];
    startpositions = Drop[FoldList[Plus, 1, lengths], -1];
    Inner[If[#1 > 1, #2, Null] &, lengths, startpositions, List] /.
      Null -> Sequence[]
    ]

dupstartpositions[list]
{3, 6, 10, 16}

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/




From: Tony King [mailto:mathstutoring at ntlworld.com]
To: mathgroup at smc.vnet.net

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: ExpToTrig with Real Numbers
  • Next by Date: Re: Questions regarding MatrixExp, and its usage
  • Previous by thread: Re: Extracting information from lists
  • Next by thread: Re: Extracting information from lists