If there are repeated elements in the list, then calling Union[]
on it will shorten it so that this element only appears once, so a simple implementation would be to test these lengths:
test[list_] := Length[Union[list]] != Length[list]
If you wanted to know which elements where repeated, you this could be accomplished by using Gather[]
to collect identical elements, and picking out which groups have more then one element.
repeats[list_] := Select[Gather[list], Length[#] > 1 &][[1 ;;, 1]]
Note, I'm using Union rather then DeleteDuplicates[]
since (as Mr. Wizard corrected me) it is faster. I can't say why except that DeleteDuplicates[]
retains the order of elements which may require slightly more bookkeeping. And in this case we don't care about the book keeping. Naturally if you really needed something really speedy, a better solution exists which doesn't search through the entire list, but stops if just a single duplicate is found, Mr. Wizards Answer is just such an function, since Signature
exits early if duplicates exist, though it becomes slower if no duplicates are present, it's a trade off.