# Finding duplicates in a list [duplicate]

I have a list of integer, and I want to know if the list contains any duplicates. My code is working, but I feel there is a more straightforward way of doing this

list1 = Range[10];
list2 = {1,2,3,4,1,6};
DoublesQ[list_] := Count[Tally[list], {_,n_}  /; n >1 ] == 0]

DoublesQ[list1]
=> True

DoublesQ[list2]
=> False


EDIT: So appears that Mathematica 10 has a function for that. I guess that now my question is: how can I do that without the build-in function?

• Length@Union@list1==Length@list1 for xample – Dr. belisarius Nov 5 '14 at 17:10
• In V10 there is DuplicateFreeQ. – Leonid Shifrin Nov 5 '14 at 17:14
• @belisarius you should post an answer – mete Nov 5 '14 at 17:31
• @mete I think this one is a dup. There was a question with some performance figures for different methods, but I can't find it now. Someone will ... – Dr. belisarius Nov 5 '14 at 17:36
• I read this, but it seemed different from what I wanted: mathematica.stackexchange.com/questions/19357/… – mete Nov 5 '14 at 17:45

New in Mathematica 10 is the function DuplicateFreeQ

list1 = Range[10];
list2 = {1,2,3,4,1,6};

DuplicateFreeQ /@ {list1, list2}
(* {True, False} *)