MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: removing subelements


Hi,

a) you have not given a valid example data set, so 
that we can't
   know what are the other members of the list 
{..,{1,2,3,4},..,{2,3},..}
   can be
b) if you only want to test a list of lists and 
remove all elements
   from that list that are sublists of the other 
lists than

RemoveSubQ[l1 : {{__Integer} ..}, l2_List] :=
Module[{tmp},
tmp = Select[l1, UnsameQ[#, l2] &];
Or @@ (RemoveSubQ[#, l2] & /@ tmp)
]
RemoveSubQ[l1_?VectorQ, l2_List] /; Length[l1] < 
Length[l2] := False
RemoveSubQ[l1_?VectorQ, l2_List] /; Length[l1] == 
Length[l2] := SameQ[l1, l2]
RemoveSubQ[l1_?VectorQ, l2_List] := 
MemberQ[Partition[l1, Length[l2], 1], l2]

RemoveSubmembers[lst_] := (If[RemoveSubQ[lst, #], 
Null, #] & /@ lst) /.
Null -> Sequence[]



may help you

with

In[]:=lst = {{1, 4, 2}, {1, 2}, {1, 2, 3, 4}, {4, 
4}, {2, 3}, {1, 2, 3}};
      RemoveSubmembers[lst]

Out[]={{1, 4, 2}, {1, 2, 3, 4}, {4, 4}}

Regards
  Jens

<borges2003xx at yahoo.it> schrieb im Newsbeitrag 
news:d3o0ta$bqn$1 at smc.vnet.net...
> 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
> 



  • Prev by Date: Re: NDSolve and InterpolatingFunction
  • Next by Date: Re: Why can't I call Random[NormalDistribution[10.0,0.0]]?
  • Previous by thread: Re: removing subelements
  • Next by thread: Re: removing subelements