How can I detect if a list contains duplicates?
问题 I want to know if a list contains any value more than once. Here's what I have. has_dupes(List) -> has_dupes(List, []). has_dupes([Item|List], Seen) -> case lists:filter(fun(Elem) -> Elem == Item end, Seen) of [] -> has_dupes(List, [Item|Seen]); _ -> true end; has_dupes([], _Seen) -> false. Is there a simpler/more concise/more idiomatic way to do this? I'm pretty new at the Erlang. 回答1: erlang:length(List) == sets:size(sets:from_list(List)). 回答2: What about this possible solution? has_dupes(