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

Alexander Lamb <>
Mon Apr 7 11:18:04 CEST 2008


Thanks, usort(Fun, List) is the solution!

(I need to sort according to my own algorithm)

Alex

Le 7 avr. 08 à 11:07, Hynek Vychodil a écrit :
>
>
> On Mon, Apr 7, 2008 at 10:51 AM, Kostis Sagonas <>  
> 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
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
>
>
> -- 
> --Hynek (Pichi) Vychodil




More information about the erlang-questions mailing list