When I'm iterating over an iterable in python, I used to keep track of where I am in the iteration more or less like so, by creating an iterator outside the loop and incrementing it within:
i = 0
for x in res:
if not(i % 10):
print("On count {}".format(unicode(i)))
f(x)
i +=1
So, on my 6 lines of loop, 4 of them are dedicated to the counter i.
I know I can also use enumerate as:
for i,x in enumerate(res):
if not(i % 10):
print("On count {}".format(unicode(i)))
f(x)
Which saves 2 lines.
I was wondering if there was /still/ a more concise way of dealing with this and providing pretty feedback to the user at some loop interval. I suspect there may be something built in to the __iter__ such that my x may be able to call some kind of count? x.___count___ or something such that I don't need to even call enumerate?
Also, does anyone have advice on providing this kind of feedback in a more functional style? How would I embed this counter in a map, rather than for-loop?