0
$\begingroup$

This question already has an answer here:

How can I select the duplicate values in a list?

Example:

{1, 2, 1, 1, 1, 1}
$\endgroup$

marked as duplicate by Öskå, Leonid Shifrin, m_goldberg, tkott, RunnyKine Jun 9 '14 at 16:22

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ I need to return the duplicate values. $\endgroup$ – BetterEnglish Jun 9 '14 at 15:07
  • $\begingroup$ So in your example what do you need to return? $\endgroup$ – Öskå Jun 9 '14 at 15:08
  • $\begingroup$ I need to return {1} $\endgroup$ – BetterEnglish Jun 9 '14 at 15:15
  • $\begingroup$ Have you even looked at the link above? It returns {1}. Please make an effort. $\endgroup$ – Öskå Jun 9 '14 at 15:17
  • $\begingroup$ @Öskå, I am so sorry! thanks $\endgroup$ – BetterEnglish Jun 9 '14 at 15:20
0
$\begingroup$

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]]
$\endgroup$

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