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


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

Re: List Manipulation

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!tudelft.nl!txtfeed1.tudelft.nl!feed.xsnews.nl!border-1.ams.xsnews.nl!newspump.sol.net!posts.news.twtelecom.net!nnrp3.twtelecom.net!not-for-mail
From "Oleksandr Rasputinov" <oleksandr_rasputinov@ymail.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: List Manipulation
Date Sun, 12 Feb 2012 10:02:47 +0000 (UTC)
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Sender steve@smc.vnet.net
Approved Steven M. Christensen <steve@smc.vnet.net>, Moderator
Message-ID <jh82o7$oi0$1@smc.vnet.net> (permalink)
References <jh6k3l$jrc$1@smc.vnet.net>
Lines 34
NNTP-Posting-Date 12 Feb 2012 10:03:44 GMT
NNTP-Posting-Host f9e1d07f.news.twtelecom.net
X-Trace DXC=kRco42B<EV48mB8O8Rk7=0C_A=>8kQj6=hHXa^^g6TZ4`l5iWPKjf87EFiONJ7[Go6^VGF4YO`<?3
X-Complaints-To abuse@twtelecom.net
Xref x330-a1.tempe.blueboxinc.net comp.soft-sys.math.mathematica:8485

Show key headers only | View raw


On Sat, 11 Feb 2012 20:46:45 -0000, 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
>

Undoubtedly there are many ways to accomplish this. Here's one using  
Distribute:

MapThread[Distribute[{##}, List, List, Sequence] &, {l1, l2}]

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

and here's one using Inner:

Inner[List, l1, Transpose[l2], Sequence]

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

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


Thread

List Manipulation Murta <rodrigomurtax@gmail.com> - 2012-02-11 20:46 +0000
  Re: List Manipulation Ray Koopman <koopman@sfu.ca> - 2012-02-12 10:02 +0000
  Re: List Manipulation "Oleksandr Rasputinov" <oleksandr_rasputinov@ymail.com> - 2012-02-12 10:02 +0000
  Re: List Manipulation Ray Koopman <koopman@sfu.ca> - 2012-02-12 10:07 +0000
  Re: List Manipulation Ray Koopman <koopman@sfu.ca> - 2012-02-12 10:07 +0000
  Re: List Manipulation Ray Koopman <koopman@sfu.ca> - 2012-02-15 09:44 +0000

csiph-web