Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #8491 > unrolled thread
| Started by | James Stein <mathgroup@stein.org> |
|---|---|
| First post | 2012-02-12 10:06 +0000 |
| Last post | 2012-02-12 10:06 +0000 |
| Articles | 1 — 1 participant |
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.
Re: List Manipulation James Stein <mathgroup@stein.org> - 2012-02-12 10:06 +0000
| From | James Stein <mathgroup@stein.org> |
|---|---|
| Date | 2012-02-12 10:06 +0000 |
| Subject | Re: List Manipulation |
| Message-ID | <jh82uu$oks$1@smc.vnet.net> |
What you want is curiously similar to the output of
Map [ { # } & , Flatten [ l1 l2 ] ]
which yields
{{a},{2 a},{3 a},{4 b},{5 b},{6 b},{7 c},{8 c},{9 c}}
But this ersatz solution has multiplied your numbers with your letters,
which I think is not what you want.
If Mathematica allowed you to override multiplication (which I think
it does not)
then this might be close to what you want; you could override multiplication:
Times [ a_, b_ ] := { a, b };
The following function, neither simple nor elegant, and unlikely to
neatly expand
to accommodate whatever problem underlies your simple question:
f [ x_ ] := Which [
Head[x/a] === Integer, {x/a, a},
Head[x/b] === Integer, {x/b, b},
Head[x/c] === Integer, {x/c, c},
True, {x}];
Would allow a one liner:
Map [ f [ # ] &, Flatten [ l1 l2 ] ]
given exactly the output you wish.
But alas, I fear all this is likely worse than your own solution.
On Sat, Feb 11, 2012 at 3: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 top | Article view | comp.soft-sys.math.mathematica
csiph-web