Re: List Partition
- To: mathgroup at smc.vnet.net
- Subject: [mg53963] Re: List Partition
- From: Roland Franzius <roland.franzius at uos.de>
- Date: Sat, 5 Feb 2005 03:15:50 -0500 (EST)
- Organization: Universitaet Hannover
- References: <ctqe1f$sf7$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
zak wrote: > 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). I take a function phrase. The definition is up to you eg. List a = {cat, E, in, the, hat, E, okay, fine, E}; Select[c = phrase[]; FoldList[If[#2 =!= E, Append[#1, #2], c = phrase[]] &, c, a # =!= phrase[] &] {phrase[cat], phrase[in], phrase[in, the], phrase[in, the, hat], phrase[okay], phrase[okay, fine]} -- Roland Franzius