[Python-Dev] Adding start to enumerate()

Brett Cannon brett at python.org
Mon May 12 01:59:48 CEST 2008


On Sun, May 11, 2008 at 4:42 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> On Mon, 12 May 2008 08:20:51 am Georg Brandl wrote:
>> I believe the following is a common use-case for enumerate()
>> (at least, I've used it quite some times):
>>
>> for lineno, line in enumerate(fileobject):
>>      ...
>>
>> For this, it would be nice to have a start parameter for enumerate().
>
> Why would it be nice? What would you use it for?
>
> The only thing I can think of is printing lines with line numbers, and
> starting those line numbers at one instead of zero. If that's the only
> use-case, should it require built-in support?

It's a common enough use-case, so I think it makes sense. With the
cost being so minimal to add support I think this one use-case alone
is enough to justify adding the support.

-Brett


More information about the Python-Dev mailing list