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
    $\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$ – Eric Towers Oct 24 at 15:16
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$
  • $\begingroup$ That's perfect! Thank you, :) $\endgroup$ – Thomas Moore Oct 23 at 23:54
  • 2
    $\begingroup$ MaximalSubsets. ResourceFunction["MaximalSubsets"][l] $\endgroup$ – Rohit Namjoshi Oct 23 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$ – Wen Chern Oct 24 at 3:05
  • $\begingroup$ @Wen, good point, thank you. Updated with your suggestion. $\endgroup$ – kglr Oct 24 at 5:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.