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

Chris Barker chris.barker at noaa.gov
Fri Oct 2 01:08:54 CEST 2015


On Thu, Oct 1, 2015 at 11:41 AM, Random832 <random832 at fastmail.com> wrote:

> > But if why do you need to know that something is an iterable, but NOT an
> > iterator? isn't that an implementation detail?
>
> Because an iterator *cannot possibly* allow you to loop through the
> contents twice [either one after the other or in parallel], whereas
> *most* non-iterator iterables do allow this. This (among other things
> such as representing a well-defined finite bag of values) is the
> property we're really chasing, "non-iterator iterable" is just a clumsy
> and inaccurate way of saying it.
>

um, then shod;nt you simply describe the iterator as an iterator?

so any "iterable" would be assumed to be a non-iterator iterable.

I guess this all comes about because we don't want to have to write this:

for i in iter(an_iterable):
    .....

i.e have a different interface for interable and an iterable

but I'm still lost on when tha all has to be spelled out...

And back the original question, for enumerate:

OK, you can't really have it e both an iterator AND a sequence, but
couldn't it be an iterator and support indexing?

Though I'm starting to wonder about the use case:

enumerate() is a way to get the items in an iterable and an index at the
same time -- so if you want to pass in a sequence, and index the result,
why not just index into the sequence in the first place??

-Chris


-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20151001/48b40f70/attachment.html>


More information about the Python-ideas mailing list