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

Random832 random832 at fastmail.com
Thu Oct 1 02:46:48 CEST 2015


Akira Li <4kir4.1i at gmail.com> writes:

> Andrew Barnert via Python-ideas
> <python-ideas at python.org> writes:
> ...
>> (The fact that we don't have a term for "non-iterator iterable", and
>
> All iterators are iterable but some iterables are not iterators.
>
> If your code accepts only iterators then use the term *iterator*.
> Otherwise the term *iterable* could be used.
>
> It is misleading to use *iterable* if your code only accepts iterators.
>
> If an iterable is an iterator; It is called *iterator*. The term
> *iterable* implies that some instances are not iterators.

There are three (well, three and a half) kinds of code that consume
iterables, how would you describe each simply?

1. Does not call iter, simply calls next. Therefore cannot consume a
   non-iterator iterable.
2. Calls iter, but can accept an iterator (e.g. only goes through it once)
3. Cannot accept an iterator (goes through it twice, or permanently
   stores a reference to it, etc)
4. Can accept either, but behaves differently in each case (e.g. zip
   when passed two of the same iterator) - this can be regarded as a
   special case of #2.



More information about the Python-ideas mailing list