Result = ordsets:to_list(ordsets:from_list([ {A,B} || {_X,_Y,A,_Z,B} <-<br>
MyList]))<br><br>Up to some size it should be faster than sets and than lists:sort<br>Other possible way is:<br><br>Result = ordsets:to_list(<br>      lists:foldl(<br>         fun(S, {_X,_Y,A,_Z,B})-> ordsets:add_element(S, {A, B});<br>
              (S, _                      )-> S<br>         end,<br>         ordsets:new(),<br>         MyList<br>      )<br>   )<br><br>Benchmark it for your purpose.<br><br><div class="gmail_quote">On Mon, Apr 7, 2008 at 10:19 AM, Alexander Lamb <alexander.lamb@rodanotech.ch> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hello (list:-)<br>
<br>
Using list comprehension, I am building a list of tuples that I want<br>
unique and sorted.<br>
<br>
Is this a correct way of doing it:<br>
<br>
Result = sets:to_list(sets:from_list([ {A,B} || {_X,_Y,A,_Z,B} <-<br>
MyList]))<br>
<br>
Then sort the Result.<br>
<br>
The alternative would be to use one of the lists functions to copy<br>
elements into a new list and testing first at each insert if the<br>
element is already present.<br>
<br>
What is best?<br>
<br>
Thanks,<br>
<br>
Alex<br>
--<br>
Alexander Lamb<br>
Founding Associate<br>
RODANOTECH Sàrl<br>
<br>
4 ch. de la Tour de Champel<br>
1206 Geneva<br>
Switzerland<br>
<br>
Tel:  022 347 77 37<br>
Fax: 022 347 77 38<br>
<br>
<a href="http://www.rodanotech.ch" target="_blank">http://www.rodanotech.ch</a><br>
<br>
<br>
<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>--Hynek (Pichi) Vychodil