MathGroup Archive 2005

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

Search the Archive

Re: removing subelements

  • To: mathgroup at smc.vnet.net
  • Subject: [mg56134] Re: removing subelements
  • From: Peter Pein <petsie at arcor.de>
  • Date: Sat, 16 Apr 2005 03:52:33 -0400 (EDT)
  • References: <d3o0ta$bqn$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

borges2003xx at yahoo.it wrote:
> 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
> 
test={{1,2,3,4},{a,b,c,d},{2,3},{3,7},{d,e,f},{1,3,7}};

Intersection@@(Complement[test,Most@Subsets[#]]&/@test)
Out[2]=
{{1,3,7},{d,e,f},{1,2,3,4},{a,b,c,d}}

If you wish the resulting list in the same order as the original, I suggest:

f[lst_List]:=
  Module[{tmp=Intersection@@(Complement[lst,Most@Subsets[#]]&/@lst)},
    Select[lst,MemberQ[tmp,#]&]]
In[4]:=
  f[test]
Out[4]=
  {{1,2,3,4},{a,b,c,d},{d,e,f},{1,3,7}}

-- 
Peter Pein
Berlin


  • Prev by Date: Re: Polar density plots
  • 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