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
> 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
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
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