1
$\begingroup$

This question already has an answer here:

I have a math problem about Mathematica, I am looking help from you. I hope that you could help me.

The Math Problem:

list= { {0,0,1},{1,0,0},{0,1,0} ,{1,2,3}};

as you know that list is a List,

and the first three elements of the list is list[[1]]、list[[2]]、list[[3]].

but the three elements of list[[1]]、list[[2]]、list[[3]] are all the same, that is 1,0,0.

the only difference is their order.

So I need a function to deal with the List:

The Results must been p={{0,0,1} ,{1,2,3}} (also can been p={{1,0,0} ,{1,2,3}},etc).

I know two functions can do that:

(1)

p = DeleteDuplicates [ list, Sort[#1] == Sort[#2] & ];

(2)

p = Union[list,  SameTest -> (SameQ[Sort[#1], Sort[#2]] &) ]

when List has 100,000 elements (Length[list]=100,000) , the speeds of these two functions

are too slow(It takes me a day, but has no results).

eg

list={};
For[i=1,i<=100000,i++,
list=Append[list,{0,0,Random[Integer,{1,5}]}]
];
p = DeleteDuplicates [ list, Sort[#1] == Sort[#2] & ];

Could you help me or give some suggestions ?

$\endgroup$

marked as duplicate by Mr.Wizard Jul 18 '14 at 12:47

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ Can you not simply sort the subsets?: DeleteDuplicates[Sort /@ set] $\endgroup$ – Mr.Wizard Jul 18 '14 at 12:39
  • $\begingroup$ Related: (3197), (17041) $\endgroup$ – Mr.Wizard Jul 18 '14 at 12:39
  • $\begingroup$ No,Can not, eg, list= { {0,0,1},{1,0,0},{0,1,0} ,{3,2,1}};When I use sort the results is {{0,0,1},{1,2,3}},But I want that {3,2,1}'s elements order cannot change. (It is element's order in finite element, so cannot change order) $\endgroup$ – YuYong Jul 18 '14 at 12:46
  • $\begingroup$ I have marked this question as a duplicate of one that I believe is equivalent. Please take a look at it. (The link is now at the top of your question.) The solution is to use GatherBy rather than DeleteDuplicates with a custom comparator, so you want: First /@ GatherBy[set, Sort]. The reason why is explained in my answer there. $\endgroup$ – Mr.Wizard Jul 18 '14 at 12:49
  • $\begingroup$ Ok,Thanks, I will look your questions carefully, Thanks! $\endgroup$ – YuYong Jul 18 '14 at 12:52