Re: Parsing awkward text in a nested list
- To: mathgroup at smc.vnet.net
- Subject: [mg107758] Re: Parsing awkward text in a nested list
- From: dh <dh at metrohm.com>
- Date: Thu, 25 Feb 2010 07:45:50 -0500 (EST)
- References: <hm56mc$k69$1@smc.vnet.net>
Hi, you may e.g. use a rule: list1 /. {{x1_, x2_}, x3 : {__}} :> {x1, StringSplit[x2, {",", " ", "{", "}"} ..], x3} Daniel On 25.02.2010 07:51, Garapata wrote: > 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. > > -- Daniel Huber Metrohm Ltd. Oberdorfstr. 68 CH-9100 Herisau Tel. +41 71 353 8585, Fax +41 71 353 8907 E-Mail:<mailto:dh at metrohm.com> Internet:<http://www.metrohm.com>