Re: Finding lengths of identical sequences in lists

*To*: mathgroup at smc.vnet.net*Subject*: [mg20270] Re: [mg20240] Finding lengths of identical sequences in lists*From*: Maris Tonso <maris at tpu.ee>*Date*: Sun, 10 Oct 1999 01:27:28 -0400*References*: <199910082230.SAA04776@smc.vnet.net.>*Sender*: owner-wri-mathgroup at wolfram.com

Hope this helps: A = {3,2,2,3,3,3,1}; Length /@ Split[A] Maris Tonso Joel Cannon wrote: > I am looking for a more elegant solution to the following. I have a > list (a list of positions at consecutive times). I wish to create a > new list of the length of each sequence of consecutive identical > members (including those of length 1). > > For example, for the list {3,2,2,3,3,3,1} I would create the list > {1,2,3,1} because the first 3 appears once, followed by two 2's, > etc. The lists I was working with contained a list of numbers > (e.g. {{x1,y1},{x2,y2},...} rather than simple numbers. I accomplished > this using a while loop, but I suspect there are better ways to do > this using pattern matching or other approaches. > > Thanks much. > > ------------------------------------------------------------------------------ > Joel W. Cannon | (724)223-6146 > Dept. of Physics | > Washington and Jefferson College | > Washington, PA 15301 | > >

**References**:**Finding lengths of identical sequences in lists***From:*Joel Cannon <jcannon@jcannon.washjeff.edu>