Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

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

Search the Archive

Re: Building List

  • To: mathgroup at smc.vnet.net
  • Subject: [mg48043] Re: Building List
  • From: "Steve Luttrell" <steve_usenet at _removemefirst_luttrell.org.uk>
  • Date: Sat, 8 May 2004 01:23:48 -0400 (EDT)
  • References: <c7fhhg$o9u$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

This does what you want:

L = { {1, 2}, {3, 4, 5, 6}, {7, 8} };

L /. {x_Integer, y1_Integer, y2 : _Integer ..} :> Apply[Sequence, Map[{x, #}
&, {y1, y2}]]

The pattern {x_Integer,y1_Integer,y2:_Integer..} matches lists of 3 or more
integers, and :> Apply[Sequence, Map[{x, #} &, {y1, y2}]] implements the
replacement that you defined.

Steve Luttrell

"Bruce W. Colletti" <bcolletti at compuserve.com> wrote in message
news:c7fhhg$o9u$1 at smc.vnet.net...
> 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: Mandelbrot Set & Mathematica
  • Next by Date: RE : Building List
  • Previous by thread: RE: Building List
  • Next by thread: RE: Building List