Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #8499

Re: List Manipulation

From Bob Hanlon <hanlonr357@gmail.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: List Manipulation
Date 2012-02-12 10:08 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <jh832q$olt$1@smc.vnet.net> (permalink)
References <201202111136.GAA16379@smc.vnet.net>

Show all headers | View raw


l1 = {a, b, c};
l2 = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};

f[a_, b_] := Flatten[{a, #}] & /@ b;

MapThread[f, {l1, l2}] // Flatten[#, 1] &

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

Flatten[Thread /@ Thread[{l1, l2}], 1]

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

% == %%

True


Bob Hanlon


On Sat, Feb 11, 2012 at 6:36 AM, Murta <rodrigomurtax@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
>

Back to comp.soft-sys.math.mathematica | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Re: List Manipulation Bob Hanlon <hanlonr357@gmail.com> - 2012-02-12 10:08 +0000
  Re: List Manipulation Murta <rodrigomurtax@gmail.com> - 2012-02-13 08:41 +0000
  Re: List Manipulation Murta <rodrigomurtax@gmail.com> - 2012-02-13 08:41 +0000
  Re: List Manipulation "Ernst H.K. Stelzer" <ernst.stelzer@physikalischebiologie.de> - 2012-02-14 11:37 +0000

csiph-web