Fastest way to count your iterations?

Paul Rubin http
Tue Jul 29 00:23:40 CEST 2003


tracer at axiomfire.com (Tracy Ruggles) writes:
> def counter(items, f, sep=1000):
> 	i = 0
> 	for item in items:
> 		f(item)
> 		i += 1
> 		if i % sep == 0:
> 			print i

How's this, if items is a sequence:

def counter(items, f, sep=1000):
   for i in xrange(0, len(items), sep):
      map(f, items[i:i+sep])
      if i > 0:
         print i




More information about the Python-list mailing list