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

Chris Angelico rosuav at gmail.com
Fri Oct 2 06:02:09 CEST 2015


On Fri, Oct 2, 2015 at 1:58 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> If you want a more practical example, any algorithm which needs to
> iterate over an interable two or more times needs to specify "iterable
> which is not an iterator".

For that particular case, I'd reiterate what others have suggested,
and use the term "reiterable" for something you can iterate over more
than once and get the same results. Sequences are normally reiterable.
Any object whose __iter__ is a generator function with stable results
will be reiterable. An iterator is not; nor is an open file object, or
any other object where iteration consumes an external resource.

This seems reasonable.

ChrisA


More information about the Python-ideas mailing list