Comment on A neater way to print something every x iterations in Python

10542107@uvlink.uvu.edu
Thu, 01 Nov 2012 20:46:18 +0000

If you only want to access every nth item you can do this.

for i in lots_of_stuff[::3]:
    do_something()

If you're not calculating progress based of how many time you've called the process function, for example you have another program doing the processing and your using it's API, then the following would work.

while True:
    for i in range(20):
        process(i)
    print( get_progress() )

Unless I was calculating progress often, I don't think I like the alternator generator, as it isn't clear what the generator does, and how to use it, and the alternative is pretty nice looking as well, however if I found myself calculating the progress a lot, then I would likely find the alternator generator to be quite useful.