Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2013

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

Search the Archive

Re: Distribute one list element over another

  • To: mathgroup at smc.vnet.net
  • Subject: [mg130482] Re: Distribute one list element over another
  • From: Bob Hanlon <hanlonr357 at gmail.com>
  • Date: Mon, 15 Apr 2013 02:28:18 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-newout@smc.vnet.net
  • Delivered-to: mathgroup-newsend@smc.vnet.net
  • References: <20130414003835.166586A91@smc.vnet.net>

data = {
   {a1, a2, a3, {m1, m2, m3, m4}},
   {b1, b2, b3, {n1, n2, n3, n4}},
   {c1, c2, c3, {o1, o2, o3, o4}},
   {d1, d2, d3, {p1, p2, p3, p4}}};



Outer[List, {First[#]},
    Last[#]][[1]] & /@ data


{{{a1, m1}, {a1, m2}, {a1, m3}, {a1, m4}}, {{b1, n1}, {b1, n2}, {b1, n3},
{b1,
    n4}}, {{c1, o1}, {c1, o2}, {c1, o3}, {c1, o4}}, {{d1, p1}, {d1, p2},
{d1,
   p3}, {d1, p4}}}



Inner[List, data[[All, 1]],
  data[[All, -1]], List] //
 Transpose


{{{a1, m1}, {a1, m2}, {a1, m3}, {a1, m4}}, {{b1, n1}, {b1, n2}, {b1, n3},
{b1,
    n4}}, {{c1, o1}, {c1, o2}, {c1, o3}, {c1, o4}}, {{d1, p1}, {d1, p2},
{d1,
   p3}, {d1, p4}}}



Bob Hanlon




On Sat, Apr 13, 2013 at 8:38 PM, Timm Reinisch <
timm.reinisch at sprechkultur.com> wrote:

> Hallo,
>
> It's difficult to explain what I want to achieve and maybe if I could
> describe it better I  would have been able to google a solution.
>
> My problem deals with lists of lists of the form {a1, a2,  a3, {m1, m2,
> m3, m4}}
>
> e.g.
>
> data =
> {
> {a1, a2,  a3, {m1, m2, m3, m4}},
> {b1, b2,  b3, {n1, n2, n3, n4}},
> {c1, c2,  c3, {o1, o2, o3, o4}},
> {d1, d2,  d3, {p1, p2, p3, p4}},
> }
>
> I want is to go over the list and transform each of the sublists {a1,
> a2,  a3, {m1, m2, m3, m4}} into a list consisting of pairs {{a1, m1},
> {a1, m2}, {a1, m3}, {a1, m4}}
> so that for the list given above I get
>
> {
> {{a1, m1},  {a1, m2}, {a1, m3}, {a1, m4}},
> {{b1, n1},  {b1, n2}, {b1, n3}, {b1, n4}},
> {{c1, o1},  {c1, o2}, {c1, o3}, {c1, o4}},
> {{d1, p1},  {d1, p2}, {d1, p3}, {d1, p4}},
> }
>
> I think it could be possible to do this using two nested map operations
> /@, but I don't find out how to do so exactly, because I run into
> trouble with the scope of the #
>
> What I'm doing at the moment is that I use a module:
>
> verteilen[liste_] := Module[{},
>   {#[[1]], liste[[1]]} & /@ liste[[4]]
> ]
>
> and map it over the list I want to transform:
>
> verteilen[#] & /@ data
>
> I'm searching for a much mor elegant way to achive this transformation,
> any hints?
>
> Thanks and best regards
>
>  Timm
>
>
>


  • Prev by Date: Re: Distribute one list element over another
  • Next by Date: Re: Distribute one list element over another
  • Previous by thread: Distribute one list element over another
  • Next by thread: Re: Distribute one list element over another