Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2012

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

Search the Archive

Re: List Manipulation

  • To: mathgroup at smc.vnet.net
  • Subject: [mg124919] Re: List Manipulation
  • From: Thomas Dowling <thomasgdowling at gmail.com>
  • Date: Sun, 12 Feb 2012 05:02:23 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <201202111136.GAA16379@smc.vnet.net>

Hello

One possibility:

Flatten[Inner[{#1, #2} &, l1, l2, List], {2}]

giving:

{{{a, 1}, {a, 2}, {a, 3}}, {{b, 4}, {b, 5}, {b, 6}}, {{c, 7}, {c, 8}, {c, 9}}}

Tom Dowling



On Sat, Feb 11, 2012 at 11:36 AM, Murta <rodrigomurtax at gmail.com> wrote:

> Hi All
>
> I'm looking some better solution for the below list manipulation:
> l1={a,b,c};
> l2={{1,2,3},{4,5,6},{7,8,9}};
> output = {{a,1},{a,2},{a,3},{b,4},{b,5},{b,6},{c,7},{c,8},{c,9}}
> It's a simple distributions of terms.
>
> I used this solution, but I think it's not an elegant one:
>
> f[a_, b_] := Flatten[{a, #}] & /@ b;
> MapThread[f, {l1, l2}] // Flatten[#, 1] &
>
> Some clue?
> Maybe with Outer or Inner?
> Thanks in advance!
> Murta
>
>


  • Prev by Date: Re: List Manipulation
  • Next by Date: Re: List Manipulation
  • Previous by thread: List Manipulation
  • Next by thread: Re: List Manipulation