I have a list of sets and some of them are equal in the sense of mathematics, but are ordered differently. How can I remove those elements from my list?

For example, the set

S=Tuples[{1, -1}, {2, 3}]

contains {{1,1,1},{1,1,-1}} and {{1,1,-1},{1,1,1}}. I want only the first of them.

This means that I want to eliminate from a set of matrices those with the same set of lines, but ordered in a different way.

The code have to work with any set generated through Tuples. (I my case, a small set of 9 x 9 matrices)


Since version 10.0, you can use DeleteDuplicatesBy with any arbitrary function to define the "Sameness". Both the function and operator form are available.


From version 7.0 onward you could do

DeleteDuplicates[S, Sort[#1] === Sort[#2] &]

As correctly pointed out by Bob Hanlon in the comments.

Mathematica graphics

  • 2
    $\begingroup$ In versions prior to v10, DeleteDuplicates[S, Sort[#1] === Sort[#2] &] $\endgroup$
    – Bob Hanlon
    Sep 27 '17 at 14:41
  • $\begingroup$ Is there a simple way to gather numbered elements (like w1, w2, w3, ..., w32) into a list (like {w1, w2, w3, ..., w32})? $\endgroup$
    – Filburt
    Sep 27 '17 at 14:45
  • $\begingroup$ @Filburt you should post another question and explain what you mean there, in detail. $\endgroup$
    – rhermans
    Sep 27 '17 at 14:46
  • $\begingroup$ @rhermans Okay =D $\endgroup$
    – Filburt
    Sep 27 '17 at 14:47

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.