[Tutor] extracting elements in a sequence

antonmuhin at rambler.ru antonmuhin at rambler.ru" <antonmuhin@rambler.ru
Mon Feb 10 07:55:02 2003


Hello Tim,

Sunday, February 9, 2003, 8:34:54 PM, you wrote:

TJ> Hello All:
TJ>     Is there a builtin way to extract elements in a series
TJ> as in 
TJ> test = [1,'one',2,'two',3,'three']
TJ> extract(test,2)
TJ> = [1,2,3]
TJ> or extract(test,3)
TJ> = [1,'two']
TJ> If so, pointers to documentation would be appreciated. 


Another solution:

def extract(seq, step):
    return [seq[i] for i in range(0, len(seq), step)]


-- 
Best regards,
 anton                            mailto:antonmuhin@rambler.ru