xrange

Roman Suzi rnd at onego.ru
Sun Jun 22 12:34:20 EDT 2003


On Sun, 22 Jun 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.
>
>timeit -s"from itertools import repeat" "for i in repeat(None, 100): pass"
>100000 loops, best of 3: 10.4 usec per loop
>
>timeit "for i in xrange(100): pass"
>100000 loops, best of 3: 11.6 usec per loop
>
>will xrange be obsoleted?  what is the best idiom for repeating a loop n
>times in 2.3 now where you don't care about the index value?

Interesting, what prevents from making xrange-object an iterator? Then there
will be obvious backward compatibility and no need to change idioms.

Sincerely yours, Roman Suzi
-- 
rnd at onego.ru =\= My AI powered by GNU/Linux RedHat 7.3






More information about the Python-list mailing list