[erlang-questions] Sets from list then to list?
Kostis Sagonas
kostis@REDACTED
Mon Apr 7 10:51:46 CEST 2008
Alexander Lamb wrote:
> Hello (list:-)
>
> Using list comprehension, I am building a list of tuples that I want
> unique and sorted.
>
> Is this a correct way of doing it:
>
> Result = sets:to_list(sets:from_list([ {A,B} || {_X,_Y,A,_Z,B} <-
> MyList]))
>
> Then sort the Result.
>
> The alternative would be to use one of the lists functions to copy
> elements into a new list and testing first at each insert if the
> element is already present.
>
> What is best?
None of the two. Check out lists:usort/1.
1> lists:usort([{1,2},{1,3},{0,1},{1,2}]).
[{0,1},{1,2},{1,3}]
Kostis
More information about the erlang-questions
mailing list