5
$\begingroup$

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?

$\endgroup$
1
  • 1
    $\begingroup$ 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. $\endgroup$ Commented Oct 24, 2019 at 15:16

1 Answer 1

7
$\begingroup$
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

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.