MathGroup Archive 1998

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

Search the Archive

Re: List Manipulation



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



  • Prev by Date: Re: Is there a 3.01 student version?
  • Next by Date: Re: Method to eliminate NIntegrate warning
  • Prev by thread: Re: List Manipulation
  • Next by thread: Re: List Manipulation