3
$\begingroup$

I have a nested list with depth 6. The items in the list are mathematical expressions. I want to find the positions of the unique items in the nested list. I have found the following, which works for a non-nested list:

positionDuplicates[list_] := GatherBy[Range@Length[list], list[[#]] &]

Ideally, the function would also count how many times the item is repeated in the nested list.

$\endgroup$
1
  • $\begingroup$ Do you know the function "Position"? $\endgroup$ Commented Aug 9 at 6:29

1 Answer 1

7
$\begingroup$
myList = {....};

myCounts = Counts[Flatten[myList]];

hh = (myList /. myCounts);

Position[hh, 1]

Test this with

myList = Table[RandomInteger[{1, 20}], {3}, {4}, {2}, {6}, {5}]
$\endgroup$
1
  • 2
    $\begingroup$ Thank you, but since the entries of the nested list are expressions, they need to be tested for equality using FullSimplify[expr1-expr2]==0 $\endgroup$
    – Morgan
    Commented Aug 9 at 5:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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