# How to delete that subset with succinct method? [duplicate]

I have a such list:

data={{4, 2}, {4, 2, 3}, {4, 5}, {4, 2, 3, 5}, {4, 6}}

Because the {4,2},{4,2,3},{4,5} is subset of {4, 2, 3, 5},so I want to delete they to get {{4,2,3,5},{4,6}}.There is mess method:

DeleteCases[data, _?(Or @@
Function[list, SubsetQ[list, #]] /@ DeleteCases[data, #] &)]

{{4,2,3,5},{4,6}}

But I think must have some concise method can do this,such as by DeleteDuplicates,Union and other something.But I have fail to implement that.

• Related converse problem: mathematica.stackexchange.com/q/8154/121 – Mr.Wizard Dec 10 '16 at 16:51
• I have marked this question as a duplicate. Please review the "original" linked at the top of your post and let me know if you disagree. – Mr.Wizard Dec 10 '16 at 16:52
• @Mr.Wizard Well,I think this two posts have little difference still,maybe they are a good reference for each other.But I will would let the reader to decide they are duplicate or not. :) – yode Dec 10 '16 at 17:35
• Please consider editing this question to highlight the difference from the existing linked question. That will automatically add this to the reopen review queue. – Mr.Wizard Dec 11 '16 at 5:30

data = {{4, 2}, {4, 2, 3}, {4, 5}, {4, 2, 3, 5}, {4, 6}};

DeleteDuplicates[SortBy[data, Length] // Reverse,
ContainsAll[#1, #2] &]

(*  {{4, 2, 3, 5}, {4, 6}}  *)

Or as yode pointed out, this can be simplified to

DeleteDuplicates[SortBy[data, Length] // Reverse, ContainsAll]

(*  {{4, 2, 3, 5}, {4, 6}}  *)
• +1)..It's seem we can omit the [#1, #2] & :) – yode Dec 9 '16 at 17:02
• Slightly simpler: DeleteDuplicates[Reverse@Sort@data, ContainsAll] (+1) – kglr Dec 10 '16 at 1:59

Also

Pick[VertexList@#, VertexInDegree@#, 1] &@ RelationGraph[SubsetQ, data]

{{4, 2, 3, 5}, {4, 6}}

Or

GraphComputation`SourceVertexList @RelationGraph[And[UnsameQ@##,SubsetQ@##]&, data]

{{4, 2, 3, 5}, {4, 6}}

• Upvote for And[UnsameQ@##, SubsetQ@##] &.I have to say I consider it for a long time to avoid produce multigraph but fail to do it. :) – yode Dec 10 '16 at 17:38
• How long have you know the package GraphComputation introduced? – yode Dec 10 '16 at 18:02