MathGroup Archive 2010

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

Search the Archive

Re: Parsing awkward text in a nested list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg107756] Re: [mg107735] Parsing awkward text in a nested list
  • From: Patrick Scheibe <pscheibe at trm.uni-leipzig.de>
  • Date: Thu, 25 Feb 2010 07:45:26 -0500 (EST)
  • References: <201002250651.BAA20661@smc.vnet.net>

Hi,

make a function which processes one element and use Map or in my
case Apply:

{#1 /. {a_, b_} :> {a, ToString /@ ToExpression[b]}, #2} & @@@ list1

Cheeers
Patrick


Am Feb 25, 2010 um 7:51 AM schrieb Garapata:

> 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: Parsing awkward text in a nested list
  • Next by Date: Re: Re: Handheld mathematica
  • Previous by thread: Parsing awkward text in a nested list
  • Next by thread: Re: Parsing awkward text in a nested list