[erlang-questions] Sets from list then to list?

Hynek Vychodil vychodil.hynek@REDACTED
Mon Apr 7 11:07:16 CEST 2008


On Mon, Apr 7, 2008 at 10:51 AM, Kostis Sagonas <kostis@REDACTED> wrote:

> 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}]
>

Yup, faster one :-)

>
>
> Kostis
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>



-- 
--Hynek (Pichi) Vychodil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080407/d8e9d07b/attachment.htm>


More information about the erlang-questions mailing list