0
$\begingroup$

I have a set where it has three subsets. I want to have each element of each subsets appears only once, sorted, but the order of subsets does not change. For example: I want to get from $$ \{\{5,2,2,3\},\{1,2,1,6\},\{7,4,5,2\}\} $$ the following $$ \{\{2,3,5\},\{1,2,6\},\{2,4,5,7\}\} $$ I did this in three times using

Union[{5,2,2,3}]

Union[{1,2,1,6}]

Union[{7,4,5,2}]

, but I guess there must be a shortcut.

Thanks.

$\endgroup$

closed as off-topic by yohbs, Kuba Apr 26 '18 at 19:44

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." – yohbs, Kuba
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 5
    $\begingroup$ Union /@ {{5, 2, 2, 3}, {1, 2, 1, 6}, {7, 4, 5, 2}}? $\endgroup$ – Fred Simons Apr 26 '18 at 18:23
  • $\begingroup$ Please read guide/ListManipulation. It is a must. $\endgroup$ – Kuba Apr 26 '18 at 19:43
2
$\begingroup$

Using Map, we have

list = {{5, 2, 2, 3}, {1, 2, 1, 6}, {7, 4, 5, 2}}
Sort /@ DeleteDuplicates /@ list

Equivalently,

Union/@list
$\endgroup$
  • $\begingroup$ Thanks. I was using the reverse one "Map[Union[list]]" :p $\endgroup$ – asad Apr 26 '18 at 19:57

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