MathGroup Archive 2005

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

Search the Archive

Re: splitting sublists

  • To: mathgroup at smc.vnet.net
  • Subject: [mg58070] Re: splitting sublists
  • From: Bill Rowe <readnewsciv at earthlink.net>
  • Date: Fri, 17 Jun 2005 05:20:23 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

On 6/16/05 at 5:38 AM, hrocht at mail15.com wrote:

>how to split the sublists inside a bigger list wherever we find
>"x" letter {{3,1,4,"x",1,5,9,2,"x"},{6,5,"x",3,5,"x",8,9,"x"}} the
>results will be:

>{{{3,1,4},{1,5,9,2}},{{6,5},{3,5},{8,9}}}

A couple of ways:

First,

In[1]:=
test = {{3, 1, 4, "x", 1, 5, 
     9, 2, "x"}, {6, 5, "x", 
     3, 5, "x", 8, 9, "x"}}; 
 
In[2]:=
ToExpression@StringReplace["{"<>ToString[#1]<>"}", 
     {", x," -> "},{", ", x}" -> "}"}]&/@test
     
Out[2]=
{{{3, 1, 4}, {1, 5, 9, 2}}, {{6, 5}, {3, 5}, {8, 9}}}

Alternatively,

In[3]:=
ReadList[StringToStream@StringReplace[StringTake[ToString@#1, 
       {2, -2}], "," -> " "], 
    Number, RecordLists -> True, RecordSeparators -> "x"]&/@ test
    
Out[3]=
{{{3, 1, 4}, {1, 5, 9, 2}}, {{6, 5}, {3, 5}, {8, 9}}}
--
To reply via email subtract one hundred and four


  • Prev by Date: Re: Transformation rule problem
  • Next by Date: Re: spotlight escape sequences
  • Previous by thread: Re: splitting sublists
  • Next by thread: Re: splitting sublists