MathGroup Archive 2001

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

Search the Archive

Re: Extract Elements from a List?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg28979] Re: Extract Elements from a List?
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Thu, 24 May 2001 04:06:56 -0400 (EDT)
  • References: <9efk6g$1d8@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com



"Robert Schuerhuber" <robert.schuerhuber at gmx.at> wrote in message
news:9efk6g$1d8 at smc.vnet.net...

> i need to extract elements from a list, starting th element number x and
> than taking every yth element, eg:
>
> with
>
> list={a,b,c,d,e,f,g,h,i,j}
> start=3;
> step=2:
>
> i'd like to get the list
>
> {c,e,g,i}.
>

Robert,

?Take

gives
....
   Take[list, {m, n, s}] gives elements m through n in steps of s.
  ...

So with,

lst={a,b,c,d,e,f,g,h,i,j};
start=3;
step=2;

we get

Take[lst, {start, -1,2}]

        {c,e,g,i}


For negative integers the position n is the -n th, counting left with the
last position given by -1.

---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565





  • Prev by Date: Re: Q: Extract Elements from a List?
  • Next by Date: RE: Q: Extract Elements from a List?
  • Previous by thread: Re: A tricky equation
  • Next by thread: Left-hand Sum, etc?