0

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?

mete
  • 1,188
  • 5
  • 16

1 Answers1

4

New in Mathematica 10 is the function DuplicateFreeQ

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

DuplicateFreeQ /@ {list1, list2}
(* {True, False} *)
chuy
  • 11,205
  • 28
  • 48