[Tutor] enumerate offset?

Chris Smith smichr at bigfoot.com
Sat Apr 30 01:15:10 CEST 2005


Does anybody else ever run into the case of using enumerate on a slice 
but then wish that the original list indices were being returned 
instead of the ones starting at zero?

I would like to see an offset argument that could be used with 
enumerate:

###
l=range(5)
for i,li in enumerate(l[3:]):
	print i, li

def myenumerate(l,offset=0):
	for i,li in enumerate(l):
		yield i+offset, li

print
for i,li in myenumerate(l[3:],3):
	print i,li
###
'''--the output--
0 3
1 4

3 3
4 4
    --end output--'''

/c



More information about the Tutor mailing list