Re: List Manipulation
- To: mathgroup@smc.vnet.net
- Subject: [mg10594] Re: List Manipulation
- From: Daniel Lichtblau <danl@wolfram.com>
- Date: Mon, 26 Jan 1998 04:42:25 -0500
- Organization: Wolfram Research, Inc.
- References: <69nbfq$89h@smc.vnet.net>
Paul.Hanson@colorado.edu wrote:
>
> 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.
>
> Paul Hanson
>
> --
> * *
> * *
> /\ */\*
> / \ / \ /\
One efficient way is to create a new list with Table.
list = {{a},{b,c},{d},{e,f,g},{h,a},{k,l,{m,n}},{o,p,q}};
In[6]:= Table[list[[2*j-1]], {j,Quotient[Length[list]+1,2]}] Out[6]=
{{a}, {d}, {h, a}, {o, p, q}}
or
In[7]:= Table[list[[j]], {j,1,Length[list],2}] Out[7]= {{a}, {d}, {h,
a}, {o, p, q}}
Daniel Lichtblau
Wolfram Research