0

How can I select the duplicate values in a list?

Example:

{1, 2, 1, 1, 1, 1}
m_goldberg
  • 107,779
  • 16
  • 103
  • 257
BetterEnglish
  • 2,026
  • 13
  • 19

1 Answers1

0

If you want all duplicates then:

list = {1, 2, 1, 1, 1, 1}

Select[Split@Sort@list, Length@# > 1 &]

if you want one from each duplicate then

Select[Split@Sort@list, Length@# > 1 &][[;;,1]]
Basheer Algohi
  • 19,917
  • 1
  • 31
  • 78