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

M.-A. Lemburg mal at egenix.com
Wed Sep 30 20:11:00 CEST 2015


On 30.09.2015 19:19, Neil Girdhar 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?

range() returns a list in Python 2 and a generator in Python 3.

enumerate() has never returned a sequence. It was one
of the first builtin APIs in Python to return a generator:

https://www.python.org/dev/peps/pep-0279/

after iterators and generators were introduced to the language:

https://www.python.org/dev/peps/pep-0234/
https://www.python.org/dev/peps/pep-0255/

The main purpose of enumerate() is to allow enumeration of
objects in a sequence or other iterable. If you need a sequence,
simply wrap it with list(), e.g. list(enumerate(sequence)).

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Experts (#1, Sep 30 2015)
>>> Python Projects, Coaching and Consulting ...  http://www.egenix.com/
>>> Python Database Interfaces ...           http://products.egenix.com/
>>> Plone/Zope Database Interfaces ...           http://zope.egenix.com/
________________________________________________________________________
2015-09-25: Started a Python blog ... ...          http://malemburg.com/
2015-10-21: Python Meeting Duesseldorf ...                 21 days to go

::::: Try our mxODBC.Connect Python Database Interface for free ! ::::::

   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611
               http://www.egenix.com/company/contact/


More information about the Python-ideas mailing list