# Removing Shorter Subsets in List of Lists

I have in Mathematica a list of lists like this:

    l={{1, 5, 9, 13, 17, 21, 25}, {2, 6, 10, 14, 18, 22, 26}, {3, 7, 11, 15,
19, 23, 27}, {4, 8, 12, 16, 20, 24}, {5, 9, 13, 17, 21, 25}, {6,
10, 14, 18, 22, 26}, {7, 11, 15, 19, 23, 27}, {8, 12, 16, 20,
24}, {9, 13, 17, 21, 25}}


There are many duplicates within the elements. For example, Element 1 has {1,5,9,13,17,21,25}, but the majority of these elements show up again in Element 5, {5,9,13,17,21,25}, and likewise with elements 2 and 7. Is it possible to remove the smaller lists with the duplicate entries?

• Since you are not removing duplicate lists, but shorter subsets of other lists, I have modified your title to match your intent. Feel free to revert if you do not agree that this change captures your intent. Oct 24, 2019 at 15:16

DeleteDuplicates[ReverseSortBy[Length] @ l, SubsetQ]


{{3,7,11,15,19,23,27},{2,6,10,14,18,22,26},{1,5,9,13,17,21,25},{4,8,12,16,20,24}}

Also

DeleteDuplicates[ReverseSortBy[Length] @ l, ContainsAll]


same result

• That's perfect! Thank you, :) Oct 23, 2019 at 23:54
• MaximalSubsets. ResourceFunction["MaximalSubsets"][l] Oct 23, 2019 at 23:58
• As a complement, the list should first be sorted according to the length of the sublists. Otherwise the larger list may be deleted. Oct 24, 2019 at 3:05
• @Wen, good point, thank you. Updated with your suggestion.
– kglr
Oct 24, 2019 at 5:00