Lists search by first element of a tuple
Erlang Questions
erlang@REDACTED
Tue Feb 7 19:53:30 CET 2006
Hi to everyone,
I want to search in a list like:
1> L=[{{1,2},3},{{1,4},3},{{2,4},8}].
[{{1,2},3},{{1,4},3},{{2,4},8}]
by the first element of the tuple that is the first element of each tuple.
Example, I can use:
2> lists:filter(fun(X) -> element(1,element(1,X)) == 1 end, L).
[{{1,2},3},{{1,4},3}]
There's a better way to perform such search?
something like:
3> lists:keysearch({1,_}, 1, L).
** 1: variable '_' is unbound **
Thanks in advance, Carlos.-
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20060207/f01e331e/attachment.htm>
More information about the erlang-questions
mailing list