[Python-Dev] Adding start to enumerate()

Nick Coghlan ncoghlan at gmail.com
Wed May 14 06:32:14 CEST 2008


Greg Ewing wrote:
> Steven D'Aprano wrote:
>> With iterators being such a fundamental part of Python these days, 
>> perhaps one day we'll see the functions in the itertools module become 
>> iterator methods
> 
> I hope not. The set of potential functions that operate
> on iterators is open-ended, and there's no reason to
> single out a particular subset and make them methods.

I've occasionally experimented with the idea of a 'FlexibleIterator' 
class that accepted an arbitrary iterable in it's constructor and then 
used itertools internally to provide native support for concatenation 
(via itertools.chain) and slicing (via itertools.islice), but have never 
been able to come up with anything which didn't lend itself to 
fundamental misunderstanding of what it was doing.

I've come to the conclusion that there are some aspects of dealing with 
arbitrary iterators where trying to make it look 'pretty' starts to hide 
things that the programmer really needs to be aware of in order to 
reason correctly about the program.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org


More information about the Python-Dev mailing list