xrange
Peter Hansen
peter at engcorp.com
Sun Jun 22 12:14:26 EDT 2003
Bryan wrote:
>
> in 2.3, what is the best way to write this:
> for i in xrange(100): print 'Hello'
>
> i used timeit and it seems that repeat is about 10% faster.
Is such a small performance difference more important to you than
backwards compatibility?
I would choose "for i in xrange()" still, merely because of the
number of people still using Python 2.2 and before, but I'm not
one who cares much about trivial optimizations...
(I realize you might be using 2.3-only features, but I don't think
that automatically means you should abandon readability, by dumping
a well-known idiom with a merely possibly-to-become-idiomatic form.)
-Peter
More information about the Python-list
mailing list