Re: List Manipulation
- To: mathgroup@smc.vnet.net
- Subject: [mg10497] Re: [mg10471] List Manipulation
- From: "Vittorio G. Caffa" <caffa@iabg.de>" <caffa@iabgmh.iabg.de>"
- Date: Tue, 20 Jan 1998 02:22:46 -0500
- Organization: IABG
Paul Hanson wrote (1) > Hola! > So, if you have a couple of lists: > {{1},{2},{3},{4}....{n}} > and > {{1a},....{na}} > and I want to combine them such that, > {{1},{1a},{2},{2a}....{n},{na}} > > How do I get there? Thanks in advance for the help. and (2) > Hola! > Hope you're all doing well. If I have a list of n lists, and want to > get rid of all the even ones how would I go about doing this? That > is, {{n1},{n2},.....{2n}} converted to {{n1},{n3}...{2n-1}}. I tried > using the various procedures in Wolfram's book, but nothing seems to > work (ie, Delete, Take, etc.). Thanks for the help. Part 1: In[1]:= aa=Array[a,7] Out[1]= {a[1],a[2],a[3],a[4],a[5],a[6],a[7]} In[2]:= bb=Array[b,7] Out[2]= {b[1],b[2],b[3],b[4],b[5],b[6],b[7]} In[3]:= cc=Flatten[Transpose[{aa,bb}]] Out[3]= {a[1],b[1],a[2],b[2],a[3],b[3],a[4],b[4],a[5],b[5], a[6],b[6],a[7],b[7]} Part 2: In[4]:= dd=Transpose[Partition[cc,2]] Out[4]= {{a[1],a[2],a[3],a[4],a[5],a[6],a[7]}, {b[1],b[2],b[3],b[4],b[5],b[6],b[7]}} Note: This works if Length[aa] == Length[bb]. If not dummy elements should be added. Cheers, Vittorio