Another question
Donald Beaudry
donb at init.com
Mon Apr 17 12:05:25 EDT 2000
Bill Scherer <scherbi at bam.com> wrote,
> I just did a little test and found this to be substantially fatser than the
> other three:
>
> import random
> randint = random.randint
>
> r = []
>
> for i in xrange(1,10000):
> r.append(randint(1,10))
>
> for i in r: print i
> #
...then this one should be really impressive ;)
def do_it():
from random import randint
r = []
append = r.append
for i in xrange(1,10000):
append(randint(i))
for i in r:
print i
do_it()
or better yet:
def do_it():
from random import randint
r = []
append = r.append
map(append, xrange(1,10000))
for i in r:
print i
do_it()
--
Donald Beaudry Ab Initio Software Corp.
201 Spring Street
donb at init.com Lexington, MA 02421
...So much code, so little time...
More information about the Python-list
mailing list