Parsing awkward text in a nested list
- To: mathgroup at smc.vnet.net
- Subject: [mg107735] Parsing awkward text in a nested list
- From: Garapata <warsaw95826 at mypacks.net>
- Date: Thu, 25 Feb 2010 01:51:37 -0500 (EST)
I have a nested list with the following dimensions: {3,2,2} It looks something like this: list1 = { {{"item1", "{ text, text, text}"}, {"item2", 24}}, {{"item1", "{ text, text, text}"}, {"item2", 24}}, {{"item1", "{ text, text, text}"}, {"item2", 24}} } I want to get the following: list2 = { {{"item1", {"text", "text", "text"}}, {"item2", 24}}, {{"item1", {"text", "text", "text"}}, {"item2", 24}}, {{"item1", {"text", "text", "text"}}, {"item2", 24}} } I've come up with a very cumbersome way to do it: Diagonal[ReplacePart[list1,{#,1,2}- >StringSplit[StringTrim[StringTrim[ list1[[All,1,2]],("{"|"}")]],","] [[#]]]&/@Range[Length[list1]]] Can anyone suggest a simpler or more elegant solution. Thx.
- Follow-Ups:
- Re: Parsing awkward text in a nested list
- From: Patrick Scheibe <pscheibe@trm.uni-leipzig.de>
- Re: Parsing awkward text in a nested list