Go back to post Create new comment

RSS Be notified of new comments on this post with the RSS feed for this post.

#

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.

for i, x in enumerate(lots_of_stuff):
    process(x)
    if i % 20 == 0:
        print "Some progress info"
Last edited by doug on Tue, 11th Aug 2009 15:25:46
#

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!

Go back to post

Create a new comment

Go to the top

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.

For post: A neater way to print something every x iterations in Python
Your name:
Your email (optional):
Your website (optional):
 
 
 

A preview of your comment:

Powered by Debian, Jack Daniels, Guinness, and excessive quantities of caffeine and sugar.