[Python-Dev] Adding start to enumerate() (original) (raw)

Steve Holden steve at holdenweb.com
Mon May 12 19:42:49 CEST 2008


Steven D'Aprano 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 fairly common in financial applications to number checks in batches, from a starting point that depends on the number of checks issued in previous runs. Having a start point would allow this to be done more simply, though it's not anyway what I would call an onerous task.

regards Steve

Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/



More information about the Python-Dev mailing list