【发布时间】:2015-11-16 10:03:59
【问题描述】:
如果我有一个列表,例如:
[{list1, [1,2]},{list2, [3,4]}]
如果将 [3,4] 作为变量传入,我将如何使用 io:format 打印出 [3,4],例如 I。
我目前正在做:
io:format("list 2: ~w~n", [I]),
【问题讨论】:
标签: list printing erlang output
如果我有一个列表,例如:
[{list1, [1,2]},{list2, [3,4]}]
如果将 [3,4] 作为变量传入,我将如何使用 io:format 打印出 [3,4],例如 I。
我目前正在做:
io:format("list 2: ~w~n", [I]),
【问题讨论】:
标签: list printing erlang output
您的示例列表格式为:[{Key1, Value1}, {Key2, Value2}, ...],其中 Key 是一个原子。这种列表也可以称为proplist(属性列表)。名为proplist 的模块可以完全处理这种数据结构。
在你的情况下,你可以运行:
PList = [{list1, [1,2]},{list2, [3,4]}],
Value = proplists:get_value(list2, PList),
io:format("list2: ~p~n", [Value]).
变量Value 现在绑定到值[3,4]。
【讨论】: