[erlang-questions] Processing a List into a Dict

Sean Cribbs seancribbs@REDACTED
Mon Nov 30 22:17:59 CET 2009


Why not do it like so:

[list_to_tuple(string:tokens(T,"=")) || T <- TXT ].

Returns:

[{"txtvers","1"},
 {"userid","3A6524D4-E31C-491D-94DD-555883B1600A"},
 {"name","Jarrod Roberson"},
 {"version","2"}]

Sean

Jarrod Roberson wrote:
> I have the following list
>
> ["txtvers=1","userid=3A6524D4-E31C-491D-94DD-555883B1600A","name=Jarrod
> Roberson","version=2"]
>
> I want to create a Dict where the left side of the = is the key and the
> right side is the value.
> Preferably where the key is an atom.
>
> Using the following list comprehension I get this.
>
>  KVL = [string:tokens(T,"=") || T <- TXT].
>
> [["txtvers","1"],
> ["userid","3A6524D4-E31C-491D-94DD-555883B1600A"], ["name","Jarrod
> Roberson"], ["version","2"]]
>
> what I am struggling with now is how to convert the nested lists into tuples
> so I can send them into a list of tuples
> where I can send them into dict:from_list
>
> what I want is something like this
>
> [{txtvers,"1"}, {userid,"3A6524D4-E31C-491D-94DD-555883B1600A"},
> {name,"Jarrod Roberson"}, {version,"2"}]
>
> I know there has to be a concise way to do this but I just can't get my head
> around it.
>
>   



More information about the erlang-questions mailing list