[docs] [issue22725] improve documentation for enumerate() (built-in function)

Van Ly report at bugs.python.org
Sat Oct 25 08:11:31 CEST 2014


Van Ly added the comment:

I don't want to argue. Ask a 12-year old and their English teacher, "Does the second sentence qualify as gobbledygook even if it is technically correct and complete and not verbose?"

To be constructive and take on what has been said, an iteration on improving the wording: 

-- improve wording as follows:

enumerate(iteratable, start=0)

Accepts an iteratable[typo for iterable?] and returns an iterator, a special case 'enumerate object'. The method iterator.next() returns a tuple which pairs an index counter with the object at the index in iterable.

>>> led = ['red', 'green', 'blue']
led = ['red', 'green', 'blue']
>>> iter = enumerate(led)
iter = enumerate(led)
>>> iter.next()
iter.next()
(0, 'red')
>>> iter.next()
iter.next()
(1, 'green')
>>> iter.next()
iter.next()
(2, 'blue')

# While enumerate does not return a list of pairs, 
# it is easy to collect the pairs and construct a list as follows
>>> list(enumerate(led))
list(enumerate(led))
[(0, 'red'), (1, 'green'), (2, 'blue')]

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22725>
_______________________________________


More information about the docs mailing list