MathGroup Archive 2005

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

Search the Archive

Re: arrange lists side by side

  • To: mathgroup at smc.vnet.net
  • Subject: [mg56565] Re: [mg56538] arrange lists side by side
  • From: DrBob <drbob at bigfoot.com>
  • Date: Fri, 29 Apr 2005 03:20:16 -0400 (EDT)
  • References: <200504280640.CAA24672@smc.vnet.net>
  • Reply-to: drbob at bigfoot.com
  • Sender: owner-wri-mathgroup at wolfram.com

a = {28, 30, 17};
b = {1, 2, 9, 4, 5, 7, 3, 8};
Transpose@{b, PadRight[a, Length@b, a]}

{{1, 28}, {2, 30}, {9, 17}, {4, 28}, {5, 30}, {7, 17}, {3, 28}, {8, 30}}

That requires knowing Length@b >= Lenght@a, but this does not:

a={28,30,17};
b={1,2,9,4,5,7,3,8};
Transpose@{PadRight[b,Max[Length/@{a,b}],b],PadRight[a,Max[Length/@{a,b}],a]}

{{1,28},{2,30},{9,17},{4,28},{5,30},{7,17},{3,28},{8,30}}

a={28,30,17,20,1,2,9,4,3,7,12};
b={1,2,9,4,5,7,3,8};
Transpose@{PadRight[b,Max[Length/@{a,b}],b],PadRight[a,Max[Length/@{a,b}],a]}

{{1,28},{2,30},{9,17},{4,20},{5,1},{7,2},{3,9},{8,4},{1,3},{2,7},{9,12}}

Bobby

On Thu, 28 Apr 2005 02:40:39 -0400 (EDT), <marloo3 at mail15.com> wrote:

> Hi
> is there a way to spread out a small list over a bigger list recurrently like
> this:
> a={28, 30, 17};
> b={1, 2, 9, 4, 5, 7, 3, 8};
> to give the output:
> {{1,28},{2,30},{9,17},{4,28},{5,30},{7,17},{3,28},{8,30}};
> the number of items in "b" do not neccesary  multiples of the number of items
> in "a"
> mark
>
> okay this is my approach
>
> a={28,30,17};
> b={1,2,9,4,5,7,3,8};
> aa={};aa=Table[Join[aa,a],{i,Length[b]/Length[a]}]
>
> Out[]=
> {{28,30,17},{28,30,17}}
>
> frc=Mod[Length[b],Length[a]];
> gg=Flatten[Join[aa,Part[a,{1,frc}]]];
> Transpose[Join[{b},{gg}]]
>
> Out[]=
> {{1,28},{2,30},{9,17},{4,28},{5,30},{7,17},{3,28},{8,30}}
>
> ----------------------------------------------------------------------
>
>
>
>
>



-- 
DrBob at bigfoot.com


  • Prev by Date: Re: Re: Re: odd mathematica blindspot
  • Next by Date: Re: arrange lists side by side
  • Previous by thread: Re: arrange lists side by side
  • Next by thread: Re: arrange lists side by side