Get loop count inside a Python FOR loop
The pythonic way is to use enumerate
:
for idx,item in enumerate(list):
Agree with Nick. Here is more elaborated code.
#count=0
for idx, item in enumerate(list):
print item
#count +=1
#if count % 10 == 0:
if (idx+1) % 10 == 0:
print 'did ten'
I have commented out the count variable in your code.