Re: Select in Math.
- To: mathgroup at smc.vnet.net
- Subject: [mg16518] Re: Select in Math.
- From: BobHanlon at aol.com
- Date: Tue, 16 Mar 1999 03:59:59 -0500
- 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.
>
Eugene,
This may be what you want.
list={{{1,2,3,4},{1,2,4,3}},{{2,3,1},{5}},{6,7}};
The nesting of the lists does not appear to be pertinent to your problem,
so simplify the structure by eliminating the nesting. Also, Sort sublists
and eliminate duplicates:
list = Union[Sort /@ {list //.
{x__List} -> Sequence[x]}]
{{5}, {6, 7}, {1, 2, 3}, {1, 2, 3, 4}}
Eliminate subsets
elements = Union[Flatten[list]];
list = Select[list, Not[Union[Flatten[
Complement[list, {#}]]] == elements]&]
{{5}, {6, 7}, {1, 2, 3, 4}}
Sort by first element
Sort[list, First[#1] < First[#2]&]
{{1, 2, 3, 4}, {5}, {6, 7}}
Bob Hanlon
- Follow-Ups:
- Re: Re: Select in Math.
- From: "Wolf, Hartmut" <hwolf@debis.com>
- Re: Re: Select in Math.