RE: Building List

*To*: mathgroup at smc.vnet.net*Subject*: [mg48036] RE: [mg48015] Building List*From*: "Harvey P. Dale" <hpd1 at nyu.edu>*Date*: Sat, 8 May 2004 01:23:40 -0400 (EDT)*Sender*: owner-wri-mathgroup at wolfram.com

Bruce: Create a function to do what you wish, e.g. - fix[lst_]:=If[Length[lst]>2,Table[{lst[[1]],lst[[i]]},{i,2,Length[lst]}],lst] Then map it to your list - fix /@ { {1,2},{3,4,5,6},{7,8} } It's better practice not to use capital letters, or initial caps, in defining your own variables or functions. That's because Mathematica, by default, uses capital letters and initial caps in defining its own variables and functions. Best, Harvey Harvey P. Dale University Professor of Philanthropy and the Law Director, National Center on Philanthropy and the Law New York University School of Law New York, N.Y. 10012-1074 -----Original Message----- From: Bruce W. Colletti [mailto:bcolletti at compuserve.com] To: mathgroup at smc.vnet.net Subject: [mg48036] [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