[Python-ideas] Consider making enumerate a sequence if its argument is a sequence

Stephen J. Turnbull stephen at xemacs.org
Thu Oct 1 09:13:06 CEST 2015


Terry Reedy writes:
 > On 9/30/2015 1:28 PM, Chris Barker wrote:
 > 
 > > But again, we could add indexing to enumerate, and have it do the ugly
 > > inefficient thing when it's using an underlying non-indexable iterator,
 > 
 > If the ugly inefficient thing is to call list(iterable), then that does 
 > not work with unbounded iterables.

I think he means

    from itertools import islice
    a = list(islice(iterable, 0, 99))[42]

 > Or the input iterable might produce inputs at various times in the
 > future.

Horrors!  We'll have to add a "block=False" parameter to next().  (We
can bikeshed on the default later.)

Seriously, I think that one we just have to live with, just as we
already live with it in any context where we access an iterable.

Regards,




More information about the Python-ideas mailing list