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