This site is best viewed in Mozilla Firefox or Google Chrome
Mon, 21st May 2012 19:29:40
Never fear, this site is here  

Go back to post Create new comment

#

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 14: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
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.