Re: split

*To*: mathgroup at smc.vnet.net*Subject*: [mg73624] Re: [mg73572] split*From*: János <janos.lobb at yale.edu>*Date*: Fri, 23 Feb 2007 04:37:05 -0500 (EST)*References*: <200702220930.EAA24214@smc.vnet.net>

On Feb 22, 2007, at 4:30 AM, Arkadiusz.Majka at gmail.com wrote: > Hi, > > I want to split a list, say > > z = {1, 3, 2, 6, 4, 7, 5,1,7}; > > into sublist of elements that are less or equal 3. > > so I want to obtain > > {{1,3,2},{6,4,7,5},{1},{7}} > > How to do it? Probably by applying Split, but what to put in Test? > > Split[z,#<=3&] gives : > > {{1, 3, 2, 6}, {4}, {7}, {5}, {1, 7}} > > Why 6 was put in first sublist together with 1, 3, and 2 since 6>3 and > should be together with 4 in the second sublist? > > Thanks, > > Arek > This one will do what you says you want in text: "into sublist of elements that are less or equal 3" In[3]:= Split[z, #1 <= 3 && #2 <= 3 & ] Out[3]= {{1, 3, 2}, {6}, {4}, {7}, {5}, {1}, {7}} This one will do what you says you want by example: "{{1,3,2}, {6,4,7,5},{1},{7}}" In[4]:= Split[z, (#1 <= 3 && #2 <= 3) || (#1 > 3 && #2 > 3) & ] Out[4]= {{1, 3, 2}, {6, 4, 7, 5}, {1}, {7}} Now, you have to make up your mind :) Fellow newbie, J=E1nos ------------------------------------------ "The shortest route between two points is the middleman" Ayn Rand

**References**:**split***From:*Arkadiusz.Majka@gmail.com