[Python-Dev] Allowing slicing of iterators

Nick Coghlan ncoghlan at iinet.net.au
Wed Jan 26 09:06:36 CET 2005


Guido van Rossum wrote:
> Iterators are for single sequential access. It's a feature that you
> have to import itertools (or at least that you have to invoke its
> special operations) -- iterators are not sequences and shouldn't be
> confused with such.
> 

I agree the semantic difference between an iterable and an iterator is 
important, but I am unclear on why that needs to translate to a syntactic 
difference for slicing, when it doesn't translate to such a difference for 
iteration (despite the *major* difference in the effect upon the object that is 
iterated over). Are the semantics of slicing really that much more exact than 
those for iteration?

Also, would it make a difference if the ability to extract an individual item 
from an iterator through subscripting was disallowed? (i.e. getting the second 
item of an iterator being spelt "itr[2:3].next()" instead of "itr[2]")

Regards,
Nick.

-- 
Nick Coghlan   |   ncoghlan at email.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://boredomandlaziness.skystorm.net


More information about the Python-Dev mailing list