2
$\begingroup$

Given the list below, I would like to find the sets within that list that are identical according to the order of their elements, generate that set, and show the number of times it appears in Lst. For example, in the below the identical sets are {N20029,N31055} which appears 2 times and {N19155,N31055} which appears 3 times.

Lst={{N20029,N31055},{N19155,N31055},{N18163,N31055},{N19155,N31055},{N18017,N31055},{N17149,N31055},{N17111,N31055},{N19155,N31055},{N20029,N31055}}
$\endgroup$

3 Answers 3

5
$\begingroup$

Tally gives you the count, and select picks only those that occur more than once.

Select[Tally[Lst], #[[2]] > 1 &]

{{{N20029, N31055}, 2}, {{N19155, N31055}, 3}}
$\endgroup$
1
  • $\begingroup$ bill s: Thank you very much!!! ... prg $\endgroup$
    – user42700
    Jun 8, 2020 at 17:04
5
$\begingroup$

Counts function also can be used for finding duplicates:

Select[Counts[Lst], # > 1 &]

<|{N20029, N31055} -> 2, {N19155, N31055} -> 3|>
$\endgroup$
1
  • $\begingroup$ very clever!! ... nice idea too! ... prg $\endgroup$
    – user42700
    Jun 8, 2020 at 19:09
0
$\begingroup$
PositionIndex[Lst]//Cases[a_:>Rule@@a/;a[[2]]>1][Transpose[{Keys[#],Length/@Values[#]}]]&
{{N20029, N31055} -> 2, {N19155, N31055} -> 3}

Or

PositionIndex[Lst]//Cases[a_/;a[[2]]>1][Transpose[{Keys[#],Length/@Values[#]}]]&
{{{N20029, N31055}, 2}, {{N19155, N31055}, 3}}
$\endgroup$

Your Answer

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

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