Re: List Partition

• To: mathgroup at smc.vnet.net
• Subject: [mg53904] Re: List Partition
• From: "Steve Luttrell" <steve_usenet at _removemefirst_luttrell.org.uk>
• Date: Wed, 2 Feb 2005 18:10:47 -0500 (EST)
• References: <ctqe1f\$sf7\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```This does what you want:

a={"cat","E","in","the","hat","E","okay","fine","E"}

Split[Split[a,#2=="E"&],Last[#1]!="E"&]/.{x_,"E"}\[Rule]{x}

Breaking this down into 3 steps gives:

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

splits the original list after each "E" to give

{{cat,E},{in},{the},{hat,E},{okay},{fine,E}}

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

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

{{{cat,E}},{{in},{the},{hat,E}},{{okay},{fine,E}}}

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

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

{{{cat}},{{in},{the},{hat}},{{okay},{fine}}}

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

{{cat},{{in},{the},{hat}},{{okay},{fine}}}

Steve Luttrell

"zak" <chocolatez at gmail.com> wrote in message
news:ctqe1f\$sf7\$1 at smc.vnet.net...
> 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