MathGroup Archive 2005

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

Search the Archive

Re: List Partition

  • To: mathgroup at
  • Subject: [mg53904] Re: List Partition
  • From: "Steve Luttrell" <steve_usenet at>
  • Date: Wed, 2 Feb 2005 18:10:47 -0500 (EST)
  • References: <ctqe1f$sf7$>
  • Sender: owner-wri-mathgroup at

This does what you want:



Breaking this down into 3 steps gives:

1. Split[a,#2=="E"&]

splits the original list after each "E" to give


2. Split[%,Last[#1]!="E"&]

then splits the above list after each sublist that ends in "E" to give


3. %/.{x_,"E"}\[Rule]{x}

then removes all the trailing "E" elements from the above sub-sublists to 


The only difference between this result and yours is that that it gives the 
more consistent {{cat}} rather than your preferred {cat}. However, if you 
really want to do things your way then add the 4th step

4. %/.{{x_}}\[Rule]{x}

to give


Steve Luttrell

"zak" <chocolatez at> wrote in message 
news:ctqe1f$sf7$1 at
> what could i do to partition the list:
> a={cat,E,in,the,hat,E,okay,fine,E}
> into
> a={{cat},{{in},{the},{hat}},{{okay},{fine}}}
> ie:  every word in a sublist , and E determine the end of a sentence
> (a bigger list).
> zak

  • Prev by Date: Nonlinear Fittings: range / boundaries are not working :(
  • Next by Date: Introduction to Programming with Mathematica, 3rd ed.
  • Previous by thread: Re: List Partition
  • Next by thread: Re: List Partition