Re: removing sublist . Again and Different

• To: mathgroup at smc.vnet.net
• Subject: [mg56349] Re: [mg56305] removing sublist . Again and Different
• From: János <janos.lobb at yale.edu>
• Date: Fri, 22 Apr 2005 06:23:42 -0400 (EDT)
• References: <200504210936.FAA05089@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

On Apr 21, 2005, at 5:36 AM, giampi1960 wrote:

> hello i read borges2003xx at yahoo.it meassage :
>
>
>> i'm a newbie. How implement the _faster functon_ which removes in a
>> list every element that are a subelement.
>> which means
>> f[x]:=  {..,{1,2,3,4},..,{2,3},..} removes {2,3}.
>> thanx a lot.
>> giorgio borghi
>
>
> i ask your help for faster way to do the opposite
> f[x]:=  {..,{1,2,3,4},..,{2,3},..} removes {1,2,3,4}.
>
> best regards
>
> giampiero

In[123]:=
result = {}

In[124]:=
lst = Table[Table[Random[
Integer, {1, 9}],
{i, 1, Random[Integer,
{1, 9}]}], {j, 1, 10}]
Out[124]=
{{8, 1, 8}, {2}, {7, 5, 4, 2,
6}, {9, 2, 9, 9, 5, 6, 5,
8}, {3, 2, 7, 8, 1, 1},
{5, 5, 6, 4, 6, 7, 1, 2},
{4, 1}, {6, 4, 6, 7, 8, 3,
5, 5}, {1, 3, 3, 2, 2},
{9, 9, 2, 4, 6}}

In[125]:=
result = First[Last[
Reap[While[lst =!= {},
srtlst = Reverse[
Sort[lst]];
srtlstmost =
Most[srtlst];
srtlstlast =
Last[srtlst];
Sow[srtlstlast];
srtlstmostpart =
(Subsets[#1,
{Length[
srtlstlast]}] & ) \
/@ srtlstmost; lst =
Pick[srtlstmost,
(If[Length[
Intersection[#1,
Permutations[
srtlstlast]]] == 0,
True, False] & ) /@
srtlstmostpart]; ]]]\
]
Out[125]=
{{2}, {4, 1}, {8, 1, 8},
{6, 4, 6, 7, 8, 3, 5, 5}}

I used here Subsets, Permutations and Intersections to match up" who
is in who".  Your criteria might be different, so feel free to change
those functions to yours.  Fast or not ?  It did away with a 1000
element list of lists in 0.10156 Second.  I am sure the statements
inside the while can be collapsed more.... if I would have more time.

János

----------------------------------------------
Trying to argue with a politician is like lifting up the head of a
corpse.
(S. Lem: His Master Voice)

• Prev by Date: Re: Re: (x-y) DiracDelta[x-y] does not simplify to 0
• Next by Date: Re: a conflicting StringReplace
• Previous by thread: Re: removing sublist . Again and Different
• Next by thread: Re: removing sublist . Again and Different