MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

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.



  • Prev by Date: Re: detection of automatic range of plot?
  • Next by Date: Controlling Memory Usage from JLink
  • Previous by thread: Installing Mathematica 7 in Linux (ferora 12 x86_64)
  • Next by thread: Re: Parsing awkward text in a nested list