[Tutor] Every Other

Alan G alan.gauld at freenet.co.uk
Mon Jun 20 10:15:45 CEST 2005


> What would be the most Pythonic way 

THats always going to be subjective but...

> of printing (or extracting) every 
> other element of a list? 

I'd probably use range with a step of 2.

for index in range(0,len(mylist),2):
   ptint mylist[index]

Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld


More information about the Tutor mailing list