# Eliminate from list of sets those that are equal (except for the order)

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.

DeleteDuplicatesBy[Sort]@S


From version 7.0 onward you could do

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


As correctly pointed out by Bob Hanlon in the comments.

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