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

Alexander Belopolsky alexander.belopolsky at gmail.com
Wed Sep 30 20:49:53 CEST 2015


On Wed, Sep 30, 2015 at 2:46 PM, Neil Girdhar <mistersheik at gmail.com> wrote:

> It doesn't behave like a generator because it doesn't implement send,
> throw, or close.


It is not a generator because Python says it is not:

>>> isinstance(range(0), collections.Generator)
False


>   It's a sequence because it implements:  __getitem__, __len__
> __contains__, __iter__, __reversed__, index, and count.


Ditto

>>> isinstance(range(0), collections.Sequence)
True
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150930/65ae5b40/attachment-0001.html>


More information about the Python-ideas mailing list