Re: Q: Extract Elements from a List?
- To: mathgroup at smc.vnet.net
- Subject: [mg28987] Re: [mg28968] Q: Extract Elements from a List?
- From: Al Kaufman <nutronstar at rickadee.net>
- Date: Thu, 24 May 2001 04:07:04 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
>hi! > >probably a very easy question, but i couldn't find an answer in the >mathematica-book: > >i need to extract elements from a list, starting th element number x and >than taking every yth element, eg: > >with > >lst={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}. > >how can i do this in the easiest way? > >regards, robert The solution is straight forward. Use the Part function as the selector: In[1]:= lst = {a, b, c, d, e, f, g, h, i, j}; start = 3; step = 2; xtr = Part[lst,Table[p,{p,start,Length[lst],step}]]; In[2]:= xtr Out[2]:= {c,e,g,i} Good luck -- ************************************** * * * Alfred Kaufman * * 802 Summerset Dr * * Rio Vista, Ca 94571 * * Phone: 707-374-4976 * * E-mail: nutronstar at rickadee.net * * * * "Reality happens a lot." * * * **************************************