Re: arrange lists side by side
- To: mathgroup at smc.vnet.net
- Subject: [mg56553] Re: arrange lists side by side
- From: "Jens-Peer Kuska" <kuska at informatik.uni-leipzig.de>
- Date: Fri, 29 Apr 2005 03:19:51 -0400 (EDT)
- Organization: Uni Leipzig
- References: <d4q1qj$oh8$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hi,
ForcePairs[lst1_, lst2_] /; Length[lst1] <
Length[lst2] := Module[{k},
k = Quotient[Length[lst2], Length[lst1]] + 1;
ll = Take[Join @@ Table[lst1, {k}],
Length[lst2]];
Transpose[{ll, lst2}]
]
ForcePairs[lst1_, lst2_] /; Length[lst1] >
Length[lst2] :=
Reverse /@ ForcePairs[lst2, lst1]
ForcePairs[lst1, lst2] := Transpose[{lst1, lst2}]
ForcePairs[b, a]
{{1, 28}, {2, 30}, {9, 17}, {4, 28}, {5, 30}, {7,
17}, {3, 28}, {8, 30}}
???
Regards
Jens
<marloo3 at mail15.com> schrieb im Newsbeitrag
news:d4q1qj$oh8$1 at smc.vnet.net...
> 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}}
>
> ----------------------------------------------------------------------
>
>