Adds an additional start argument to the built-in enumerate function.
1 2 3 4 5 6 7 8 9
from itertools import izip, count def enumerate(a, b=None): "enumerate([start,] iterable)" if b is None: start, iterable = 0, a else: start, iterable = a, b return izip(count(start), iterable)
Presenting a more general solution to the loop counter problem "because sometimes you don't want to start counting from zero": <pre> for checknum, check in enumerate(lastchecknum, checks): printdraft(check, checknum)
myfile = open(myfilename) for lineno, line in enumerate(myfile): print '%4d: %s' % (lineno, line) </pre>
This should run just as fast as the built-in version of enumerate().