1
$\begingroup$

I've got a table of tables: $A=\{\{a,b\},\{b,a\},...,\{a,b,c,d,e\},\{e,d,c,a,b\},...\}$. How do I do to remove backward duplicates, or more generally permutations of duplicates in the table?

For example in $A$ I want to erase one of $\{a,b\},\{b,a\}$, and $\{a,b,c,d,e\},\{e,d,c,a,b\}$. Which could be the shortest way to do that? I don't mind which is the erased element...

$\endgroup$

closed as off-topic by Dr. belisarius, ciao, xyz, Kuba, Michael E2 Apr 10 '15 at 10:15

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Dr. belisarius, ciao, xyz
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    $\begingroup$ DeleteDuplicates[list, Sort@#1 == Sort@#2 &] - and don't use uppercase initials for your own symbols (like A)... $\endgroup$ – ciao Apr 10 '15 at 3:29
  • 1
    $\begingroup$ DeleteDuplicates[Sort/@A] looks like it would be faster, if you don't mind the sub lists being sorted afterwards. $\endgroup$ – Sjoerd C. de Vries Apr 10 '15 at 5:48
  • 1
    $\begingroup$ Proposed duplicate: (44). Related: (1302), (5799), (17041) $\endgroup$ – Mr.Wizard Apr 10 '15 at 6:09
4
$\begingroup$

Perhaps something as simple as

data = {{a, b}, {b, a}, {a, b, c, d, e}, {e, d, c, a, b}};
Union[Sort /@ data]
{{a, b}, {a, b, c, d, e}}
$\endgroup$
  • $\begingroup$ Keep it small and simple... +1! $\endgroup$ – mgamer Apr 10 '15 at 5:38
0
$\begingroup$

Or this:

lst = {{a, b}, {b, a}, {a, b, c, d, e}, {e, d, c, a, b}};
DeleteDuplicates[Sort/@lst]
(* {{a, b}, {a, b, c, d, e}} *)
$\endgroup$

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