Re: List Partition
- To: mathgroup at smc.vnet.net
- Subject: [mg53932] Re: [mg53895] List Partition
- From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
- Date: Fri, 4 Feb 2005 04:11:57 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
>-----Original Message----- >From: zak [mailto:chocolatez at gmail.com] To: mathgroup at smc.vnet.net >Sent: Wednesday, February 02, 2005 12:26 PM >To: mathgroup at smc.vnet.net >Subject: [mg53932] [mg53895] List Partition > >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 > > In[14]:= r1 = Split[a, #1 =!= "E" &] Out[14]= {{"cat", "E"}, {"in", "the", "hat", "E"}, {"okay", "fine", "E"}} In[15]:= r2 = Drop[r1, {}, {-1}] Out[15]= {{"cat"}, {"in", "the", "hat"}, {"okay", "fine"}} In[16]:= Map[List, r2, {2}] Out[16]= {{{"cat"}}, {{"in"}, {"the"}, {"hat"}}, {{"okay"}, {"fine"}}} -- Hartmut Wolf