Convert nested Lists into a List of Tuples - Erlang


/ Published in: Other
Save to your folder(s)



Copy this code and paste it in your HTML
  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"}]

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.