0
$\begingroup$

What are the convenient Mathematica functions, say $Func1$ and $Func2$, that if one inputs a collection of sets of numbers:

$$\text{{{1,2},{3,2},{4,1},{1,2},{1,2},{4,1}}}$$

(1) $$\text{$Func1$[{{1,2},{3,2},{4,1},{1,2},{1,2},{4,1}}]={{1,2},{3,2},{4,1}},}$$ outputs a collection of distinct sets of numbers.

(2) $$\text{$Func2$[{{1,2},{3,2},{4,1},{1,2},{1,2},{4,1}}],}$$ outputs a collection of distinct sets of numbers {{1,2},{3,2},{4,1}}, but also counts the number of such a sets? Namely $Func2$ outputs knowing 3 sets of {1,2}, 1 set of {3,2}, 2 sets of {4,1}}. but with more information that {3,1,2} stands for the number of collection for each sets.

$\endgroup$
  • 2
    $\begingroup$ Next time please post code as copyable code, not as LaTeX. This is so that people can transfer the expressions into their notebooks without re-typing them. $\endgroup$ – Szabolcs Mar 2 '17 at 18:06
  • 5
    $\begingroup$ Use Counts in v10 or Tally in earlier versions. There's also DeleteDuplicates and Union. $\endgroup$ – Szabolcs Mar 2 '17 at 18:07
1
$\begingroup$

$Func1$ can be Union:

In:= Union[{{1, 2}, {3, 2}, {4, 1}, {1, 2}, {1, 2}, {4, 1}}]

Out= {{1, 2}, {3, 2}, {4, 1}}

$Func2$ can be Tally and then Sort:

In:= Tally[{{1, 2}, {3, 2}, {4, 1}, {1, 2}, {1, 2}, {4, 1}}]

Out= {{{1, 2}, 3}, {{3, 2}, 1}, {{4, 1}, 2}}

In:= Sort[Tally[{{1,2},{3,2},{4,1},{1,2},{1,2},{4,1}}]]

Out= {{{1,2},3},{{3,2},1},{{4,1},2}}
$\endgroup$

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