Re: arrange lists side by side
- To: mathgroup at smc.vnet.net
- Subject: [mg56556] Re: [mg56538] arrange lists side by side
- From: "Caffa Vittorio Dr." <Caffa at iabg.de>
- Date: Fri, 29 Apr 2005 03:19:55 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Here is a shorter solution: In[1]:= a = {28, 30, 17}; In[2]:= b = {1, 2, 9, 4, 5, 7, 3, 8}; In[3]:= MapIndexed[{#1, a[[Mod[#2[[1]], Length[a], 1]]]} &, b] Out[3]= {{1, 28}, {2, 30}, {9, 17}, {4, 28}, {5, 30}, {7, 17}, {3, 28}, {8, 30}} Cheers, Vittorio >-----Original Message----- >From: marloo3 at mail15.com [mailto:marloo3 at mail15.com] To: mathgroup at smc.vnet.net >Sent: Thursday, April 28, 2005 8:41 AM >Subject: [mg56556] [mg56538] arrange lists side by side > >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}} > >---------------------------------------------------------------------- >