Be notified of new comments on this post with the RSS feed for this post.
Err, true - that was a typo.. Fixed..
list = range(1,100) result = filter(lambda y: sys.stdout.write("progress info\n"), filter(lambda x: x % 10 == 0, list))
TADA!
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.
You can use a restricted version of markdown formatting here. You can use the toolbar above the text field to make this more painless. For more information about markdown please refer to the markdown cheatsheet.
That's neat but two things should be that enumerate isn't automatically applied in Python 2.3 to 2.5 and it doesn't appear to be in 2.6 either.. what version of Python is that code for? You need to explicitly call enumerate() in the versions I tested.