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


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

Re: List Manipulation

Started byBob Hanlon <hanlonr357@gmail.com>
First post2012-02-12 10:08 +0000
Last post2012-02-14 11:37 +0000
Articles 4 — 3 participants

Back to article view | Back to comp.soft-sys.math.mathematica

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  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

#8499 — Re: List Manipulation

FromBob Hanlon <hanlonr357@gmail.com>
Date2012-02-12 10:08 +0000
SubjectRe: List Manipulation
Message-ID<jh832q$olt$1@smc.vnet.net>
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
>

[toc] | [next] | [standalone]


#8508

FromMurta <rodrigomurtax@gmail.com>
Date2012-02-13 08:41 +0000
Message-ID<jhaib2$528$1@smc.vnet.net>
In reply to#8499
I get a lot of new ideas for manipulate lists with these post!
Thanks for all!..

[toc] | [prev] | [next] | [standalone]


#8521

FromMurta <rodrigomurtax@gmail.com>
Date2012-02-13 08:41 +0000
Message-ID<jhaic1$52r$1@smc.vnet.net>
In reply to#8499
Mixing some posts, I get this solution:

Join@@Thread/@Thread@{l1, l2}

tks
Murta

[toc] | [prev] | [next] | [standalone]


#8529

From"Ernst H.K. Stelzer" <ernst.stelzer@physikalischebiologie.de>
Date2012-02-14 11:37 +0000
Message-ID<jhdh1s$h9d$1@smc.vnet.net>
In reply to#8499
In[4]:= Join @@
 Thread /@ Thread@{{1, 2, 3, 4, 5, 6}, {a, b, c, d, e, f}}

Out[4]= {1, a, 2, b, 3, c, 4, d, 5, e, 6, f}

In[6]:= Transpose[{{1, 2, 3, 4, 5, 6}, {a, b, c, d, e, f}}] // Flatten

Out[6]= {1, a, 2, b, 3, c, 4, d, 5, e, 6, f}

In[7]:= Riffle[{1, 2, 3, 4, 5, 6}, {a, b, c, d, e, f}]

Out[7]= {1, a, 2, b, 3, c, 4, d, 5, e, 6, f}

Sincerely

    E. Stelzer

Prof. Dr. Ernst H.K. Stelzer
Physikalische Biologie/Physical Biology (FB 15, IZN)
Buchmann Institute for Molecular Life Sciences (FMLS, CEF-MC)
Goethe Universit=E4t Frankfurt am Main (Campus Riedberg)
Max-von-Laue Strasse 15
D-60438 Frankfurt am Main, Germany

Tel   +49 (69) 798 42547, x42555, x42544
Fax   +49 (69) 798 42546
Mob +49 (170) 6357 168

http://www.fmls-institute.de http://www.uni-frankfurt.de
http://www.researcherid.com/rid/A-7648-2011
ernst.stelzer@physikalischebiologie.de
stelzer@bio.uni-frankfurt.de

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web