Re: Select in Math.
- To: mathgroup at smc.vnet.net
- Subject: [mg16576] Re: Select in Math.
- From: "Allan Hayes" <hay at haystack.demon.co.uk>
- Date: Wed, 17 Mar 1999 23:54:55 -0500
- References: <7clc04$9k0@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
In a message dated 3/8/99 6:43:38 PM, kewjoi at hixnet.co.za writes: >My question is how can I extract (select) list of lists in increasing >order? >For example: >In[2]:=list={{{1,2,3,4},{1,2,4,3}},{{2,3,1},{5}},{6,7}} >Out[2]={{{1,2,3,4},{1,2,4,3}},{{2,3,1},{5}},{6,7}} > >I 'd like to obtain only the parts in increased order, therefore the >result should be : >Out[3]={{1,2,3,4},{5},{6,7}} >I did try (Cases, Select, and Extract) but definitely not in proper way. > One problem is that the lists that you seek seem to be at different levels. We can tackle this either by specifying the pattern of these lists: list={{{1,2,3,4},{1,2,4,3}},{{2,3,1},{5}},{6,7}}; Cases[list,{___Integer}? OrderedQ, Infinity ] {{1,2,3,4},{5},{6,7}} Or by noting that they are all in fact at level -2 (this is probably the quicker way) Cases[list,_?OrderedQ, {-2} ] {{1,2,3,4},{5},{6,7}} Allan --------------------- Allan Hayes Mathematica Training and Consulting Leicester UK www.haystack.demon.co.uk hay at haystack.demon.co.uk Voice: +44 (0)116 271 4198 Fax: +44 (0)870 164 0565