Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

This question already has an answer here:

How can I select the duplicate values in a list?


{1, 2, 1, 1, 1, 1}
share|improve this question

marked as duplicate by Öskå, Leonid Shifrin, m_goldberg, tkott, RunnyKine Jun 9 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.

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

1 Answer 1

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]]
share|improve this answer
add comment

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