Re: Building List

• To: mathgroup at smc.vnet.net
• Subject: [mg48031] Re: Building List
• From: astanoff_otez_ceci at yahoo.fr (astanoff)
• Date: Sat, 8 May 2004 01:23:35 -0400 (EDT)
• References: <c7fhhg\$o9u\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Bruce W. Colletti wrote:
> Re Mathematica 5.0.1.0.
> I have a list of lists -- e.g., L = { {1,2},{3,4,5,6},{7,8} } -- and
> want to replace element-lists (whose length exceeds 2) with another list
> built from that element.  All else is untouched.
> For instance, using L above, replace {3,4,5,6} with {3,4}, {3,5}, {3,6}.
>  This transforms L to the desired form { {1,2}, {3,4}, {3,5}, {3,6},
> {7,8} }.
> Although I can do this using Sow and Reap, am hoping there's an easier
> way using rules (/.).  In general, I want to replace those L-elements x
> (that meet a criterion) with foo[x].
> Thanks.
> Bruce

In[1]:= myRule=
{a___, b_List /; Length[b] > 2, c___} :>
{a, Sequence @@ Thread[{First[b],Rest[b]}],c};

In[2]:= { {1,2},{3,4,5,6},{7,8} } /. myRule
Out[2]={{1,2},{3,4},{3,5},{3,6},{7,8}}

--
0% de pub! Que du bonheur et des vrais adhérents !
Vous aussi inscrivez-vous sans plus tarder!!
Message posté à partir de http://www.gyptis.org, BBS actif depuis 1995.

```

• Prev by Date: Re: plot data points onto sphere
• Next by Date: RE: Building List
• Previous by thread: Re: Building List
• Next by thread: RE: Building List