[erlang-questions] Processing a List into a Dict

Jarrod Roberson <>
Mon Nov 30 22:26:08 CET 2009


On Mon, Nov 30, 2009 at 4:24 PM, Zoltan Lajos Kis <> wrote:

> KVL = [begin [K,V]=string:tokens(T,"="), {list_to_atom(K), V} end || T <-
> L].
> If this feels ugly, you can move the begin-end part to a separate list.
>
> If you only need this list for creating a dictionary, you can also foldl on
> your original list:
>
> lists:foldl(fun(T, D) ->
>               [K,V] = string:tokens(T, "="),
>               dict:store(list_to_atom(K), V, D)
>             end,
>             dict:new(),
>             L).
>
> Regards,
> oltan.
>
>
thanks this is even more compact than what I came up with, I knew there was
some fancy one line way of doing this.


More information about the erlang-questions mailing list