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$
3
  • 1
    $\begingroup$ DeleteDuplicates[list, Sort@#1 == Sort@#2 &] - and don't use uppercase initials for your own symbols (like A)... $\endgroup$ Commented Apr 10, 2015 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$ Commented Apr 10, 2015 at 5:48
  • 1
    $\begingroup$ Proposed duplicate: (44). Related: (1302), (5799), (17041) $\endgroup$ Commented Apr 10, 2015 at 6:09

2 Answers 2

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$
1
  • $\begingroup$ Keep it small and simple... +1! $\endgroup$ Commented Apr 10, 2015 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$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.