MathGroup Archive 2004

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

Search the Archive

RE : Building List

  • To: mathgroup at smc.vnet.net
  • Subject: [mg48033] RE : [mg48015] Building List
  • From: "Florian Jaccard" <florian.jaccard at eiaj.ch>
  • Date: Sat, 8 May 2004 01:23:37 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Hello !

There are a lot of ways...

For example :

In[47]:=
exemple = {{1, 2}, {3, 4, 5, 6}, {7, 8}, {9, 10, 11}}; 

In[52]:=
Clear[f]; 
f[li_ /; Length[li] > 2] := ({First[li], #1} & ) /@ 
    Drop[li, 1]; 
f[li_] := {li}; 

In[55]:=
Flatten[f /@ exemple, 1]

Out[55]=
{{1, 2}, {3, 4}, {3, 5}, {3, 6}, {7, 8}, {9, 10}, 
  {9, 11}}

Meilleures salutations
 
F.Jaccard


-----Message d'origine-----
De : Bruce W. Colletti [mailto:bcolletti at compuserve.com] 
Envoyé : vendredi, 7. mai 2004 10:30
À : mathgroup at smc.vnet.net
Objet : [mg48015] Building List

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




  • Prev by Date: Re: Building List
  • Next by Date: Re: Simple question
  • Previous by thread: Re: Interpretation of subscripts
  • Next by thread: Re: FindRoot cannot find obvious solution