On Wed, Sep 30, 2015 at 10:19 AM, Neil Girdhar email@example.com wrote:
I guess, I'm just asking for enumerate to go through the same change that range went through. Why wasn't it a problem for range?
well, range is simpler -- you don't pass arbitrary iterables into it. It always has to compute integer values according to start, stop, step -- easy to implement as either iteration or indexing.
enumerate, on the other hand, takes an arbitrary iterable -- so it can't just index into that iterable if asked for an index.
You are right, of course, that it COULD do that if it was passed a sequence in the first place, but then you have an intera e whereby you get a different kind of object depending on how you created it, which is pretty ugly.
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, and do the efficient thing when it has a sequence to work with, thereby providing the same API regardless.
On Wed, Sep 30, 2015 at 1:18 PM Neil Girdhar firstname.lastname@example.org wrote:
Ah good point. Well, in the case of a sequence argument, an enumerate object could be both a sequence and an iterator.
On Wed, Sep 30, 2015 at 1:15 PM Alexander Belopolsky < email@example.com> wrote:
On Wed, Sep 30, 2015 at 12:53 PM, Neil Girdhar firstname.lastname@example.org wrote:
A Sequence is an Iterator.
No, a Sequence is an Iterable, not an Iterator:
Python-ideas mailing list Pythonemail@example.com https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/