關於到文檔proplists:lookup_all
工作其他方式:
Returns the list of all entries associated with Key in List.
所以,您可以通過按鍵只查找:
([email protected])1> Db = [{james,london},{fredrik,berlin},{fred,berlin}].
[{james,london},{fredrik,berlin},{fred,berlin}]
([email protected])2> proplists:lookup_all(berlin, Db).
[]
([email protected])3> proplists:lookup_all(fredrik, Db).
[{fredrik,berlin}]
您可以使用lists:filter
和lists:map
inste廣告:
([email protected])7> lists:filter(fun ({K, V}) -> V =:= berlin end, Db).
[{fredrik,berlin},{fred,berlin}]
([email protected])8> lists:map(fun ({K,V}) -> K end, lists:filter(fun ({K, V}) -> V =:= berlin end, Db)).
[fredrik,fred]
所以,最後
match(Element, Db) -> lists:map(
fun ({K,V}) -> K end,
lists:filter(fun ({K, V}) -> V =:= Element end, Db)
).
好吧,我現在明白了。我不知道,我可以用列表:過濾器,同時具有在列表中的元組。非常感謝您的快速和明確的答案! – user1213904