[issue2831] Adding start to enumerate()

Nick Coghlan report at bugs.python.org
Tue May 13 11:50:06 CEST 2008


Nick Coghlan <ncoghlan at gmail.com> added the comment:

Note that this functionality is currently available as follows:

>>> from itertools import count
>>> list(zip(count(3), 'abcdefg')
[(3, 'a'), (4, 'b'), (5, 'c'), (6, 'd'), (7, 'e'), (8, 'f'), (9, 'g')]

The enumerate(itr) builtin is just a convenience to avoid a module
import for the most basic zip(count(), itr) version.

The proposed patch would enable the example above to be written more
verbosely as:

>>> list(enumerate('abcdefg', start=3))

Or, with the positional argument approach as:

>>> list(enumerate(3, 'abcdefg'))


So, more verbose than the existing approach, and ambiguous to boot - as
Raymond noted, with the first it really isn't clear whether the first
value returned would be (3, 'd') or (3, 'a'), and with the second form
it isn't clear whether we're skipping the first three items, or
returning only those items.

Let's keep the builtins simple, and let itertools handle the variants -
that's why the module exists.

----------
nosy: +ncoghlan

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue2831>
__________________________________


More information about the Python-bugs-list mailing list