Posted By

fuzzylollipop on 11/30/09


Tagged

erlang


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

fuzzylollipop


Convert nested Lists into a List of Tuples - Erlang


 / Published in: Other
 

URL: http://stackoverflow.com/questions/1822405/convert-nested-lists-into-a-list-of-tuples/1822439

  1. TXT = ["txtvers=1","userid=3A6524D4-E31C-491D-94DD-555883B1600A","name=Jarrod Roberson","version=2"].
  2.  
  3. A = [ string:tokens(KV,"=") || KV <- TXT].
  4. [["txtvers","1"],
  5. ["userid","3A6524D4-E31C-491D-94DD-555883B1600A"],
  6. ["name","Jarrod Roberson"],
  7. ["version","2"]]
  8.  
  9. D = [{list_to_atom(K),V} || [K|[V|_]] <- A].
  10. [{txtvers,"1"},
  11. {userid,"3A6524D4-E31C-491D-94DD-555883B1600A"},
  12. {name,"Jarrod Roberson"},
  13. {version,"2"}]

Report this snippet  

You need to login to post a comment.