Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Erlang 如何在列表中获取元组?_Erlang - Fatal编程技术网

Erlang 如何在列表中获取元组?

Erlang 如何在列表中获取元组?,erlang,Erlang,我想知道如何使用lists:filter从元组列表中获取特定的元组。 我的代码是: myFilter(Item,List)-> MyItems = lists:map(fun(X)-> element(2,X) end,List), lists:filter(fun()-> lists:member(Item,MyItems) end , List). 例如: myFilter(1,[{atom1,1,"P1"},{atom2,2,"P1"

我想知道如何使用lists:filter从元组列表中获取特定的元组。 我的代码是:

myFilter(Item,List)->
         MyItems = lists:map(fun(X)-> element(2,X) end,List),
         lists:filter(fun()-> lists:member(Item,MyItems) end , List).
例如:

myFilter(1,[{atom1,1,"P1"},{atom2,2,"P1"},{atom3,3,"P3"}]) = {atom1,1,"P1"}
列表:keyfind就是为了这个!List:keyfind1,2,List将返回列表中第二项为1的第一个元组,如果未找到任何元组,则返回false:

1> List = [{atom1,1,"P1"},{atom2,2,"P1"},{atom3,3,"P3"}].
[{atom1,1,"P1"},{atom2,2,"P1"},{atom3,3,"P3"}]
2> lists:keyfind(1, 2, List).
{atom1,1,"P1"}
列表:keyfind就是为了这个!List:keyfind1,2,List将返回列表中第二项为1的第一个元组,如果未找到任何元组,则返回false:

1> List = [{atom1,1,"P1"},{atom2,2,"P1"},{atom3,3,"P3"}].
[{atom1,1,"P1"},{atom2,2,"P1"},{atom3,3,"P3"}]
2> lists:keyfind(1, 2, List).
{atom1,1,"P1"}