<p dir="ltr">Others have given good answers.<br>
For completeness, I thought I'd mention this:<br>
Your example<br>
[ Value || {Name, Value} <- A, string:equal(Name, "name3")].<br>
could be simplified to:<br>
[ Value || {"name3", Value} <- A].</p>
<p dir="ltr">Note that both result in a list.</p>
<p dir="ltr">Huh. Question to the list: I realize that I don't know how string:equal() differs from using '=:='... The docs don't tell explicitly. Is there a difference? </p>
<div class="gmail_quote">Den 25/02/2014 15.13 skrev "Oleg" <<a href="mailto:lego12239@yandex.ru">lego12239@yandex.ru</a>>:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
š Hello.<br>
<br>
I'm erlang newbie. Don't beat me, please :-), if this question is obvious.<br>
<br>
I have a list of key-value pairs:<br>
<br>
A=[{"name1", 1}, {"name2", 77}, {"name3", 33}, {"name4", 234}].<br>
<br>
What is faster:<br>
<br>
[ Value || {Name, Value} <- A, string:equal(Name, "name3")].<br>
<br>
Or:<br>
<br>
get_value(Key, []) -><br>
š [].<br>
get_value(Key, [H|T]) -><br>
š {Name, Value} = H,<br>
š case string:equal(Name, Key) of<br>
š š true -><br>
š š š [Value];<br>
š š false -><br>
š š š get_value(Key, T)<br>
š end.<br>
<br>
start() -><br>
š get_value("name3", A).<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</blockquote></div>