> Erlang中文手册 > keymember/3 判断是否是元组列表里的成员

lists:keymember/3

判断是否是元组列表里的成员

用法:

keymember(Key, N, TupleList) -> bool()

内部实现:

%% Shadowed by erl_bif_types: lists:keymember/3
-spec keymember(Key, N, TupleList) -> boolean() when
      Key :: term(),
      N :: pos_integer(),
      TupleList :: [Tuple],
      Tuple :: tuple().

keymember(_, _, _) ->
    erlang:nif_error(undef).

判断元组列表 TupleList 里元组的第 N 个值里是否有 Key 这个值存在

TupleList = [{a, 1}, {b, 2}, {c, 3}, {d, 4}],
lists:keymember(b, 1, TupleList).