Re: [Tutor] Every Other

2005-06-20 Thread Alan G
JOhn, > This is probably it: > >>> arr = range(20) > >>> arr[::2] You are probably right, I forgot that slicing now had a 3rd element... :-) Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Every Other

2005-06-20 Thread Alan G
> 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 tuto

Re: [Tutor] Every Other

2005-06-19 Thread jfouhy
Quoting Chuck Allison <[EMAIL PROTECTED]>: > Hello Tutors, > > What would be the most Pythonic way of printing (or extracting) every > other element of a list? Thanks in advance. This is probably it: >>> arr = range(20) >>> arr[::2] [0, 2, 4, 6, 8, 10, 12, 14, 16, 18] >>> arr[1::2] [1, 3, 5, 7

[Tutor] Every Other

2005-06-19 Thread Chuck Allison
Hello Tutors, What would be the most Pythonic way of printing (or extracting) every other element of a list? Thanks in advance. -- Chuck Allison ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor