[erlang-questions] Sorting of lists

Jordan Wilberding diginux@REDACTED
Thu Apr 19 20:21:37 CEST 2007


MyList = [ {3, ceasar}, {1, adam}, {4, david}, {2, billy}],
lists:sort(fun({_,L}, {_,R}) -> L =< R end, MyList).

Thanks!
Jordan Wilberding

Fredrik Hoback wrote:
> Hi, I've this problem:
>
> If you have a list containing elements like this:
> Names = [adam, billy, ceasar, david]
>
> and then I have another list:
>
> MyList = [ {3, ceasar}, {1, adam}, {4, david}, {2, billy}]
>
> then I would like to order MyList according to Names, so MyList would
> look like this:
>
> [{1, adam}, {2, billy}, {3, ceasar},  {4, david}].
>
> How would a function look like to get MyList sorted according to Names ?
> ---------------------------------
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>   




More information about the erlang-questions mailing list