<br><br><div class="gmail_quote">On Mon, Apr 7, 2008 at 10:51 AM, Kostis Sagonas <<a href="mailto:kostis@cs.ntua.gr">kostis@cs.ntua.gr</a>> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="Ih2E3d">Alexander Lamb wrote:<br>
> 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>
</div>None of the two. Check out lists:usort/1.<br>
<br>
1> lists:usort([{1,2},{1,3},{0,1},{1,2}]).<br>
[{0,1},{1,2},{1,3}]<br>
<font color="#888888"></font></blockquote><div><br>Yup, faster one :-) <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><font color="#888888"><br>
<br>
Kostis<br>
</font><div><div></div><div class="Wj3C7c">_______________________________________________<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>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>--Hynek (Pichi) Vychodil