[Tutor] extracting elements in a sequence

alan.gauld@bt.com alan.gauld@bt.com
Mon Feb 10 05:47:02 2003


> As far as I know there is no built-in way to extract the nth 
> element out of a list, but it is very simple to write a function 
> to do this for you:
> 
def extract (oldlist, spacing):
     newlist = []
     for i in range(0,len(oldlist),spacing):
        newlist.append(oldlist[i])
     return newlist

Should do it?

Alan g.
Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld/