> Erlang中文手册 > fetch_keys/1 获取字典里所有键

dict:fetch_keys/1

获取字典里所有键

用法:

fetch_keys(Dict) -> Keys

内部实现:

-spec fetch_keys(Dict) -> Keys when
      Dict :: dict(),
      Keys :: [term()].

fetch_keys(D) ->
    fold(fun (Key, _Val, Keys) -> [Key|Keys] end, [], D).

以列表的形式返回字典里所有的键

D = dict:from_list([{k1, v1}, {k2, v2}, {k3, v3}]),
dict:fetch_keys(D).