[Tutor] List comprehension question

David Hutto smokefloat at gmail.com
Fri Nov 12 14:15:24 CET 2010

>        repeatedly, returning a list of results. ...
> I'm sorry, Steven, but I could you revise this code to use repeat=5
> instead of the for loop? I can't see how to do it.

>>> help(timeit.Timer

 repeat(self, repeat=3, number=1000000)
 |      Call timeit() a few times.
 |      This is a convenience function that calls the timeit()
 |      repeatedly, returning a list of results.  The first argument
 |      specifies how many times to call timeit(), defaulting to 3;
 |      the second argument specifies the timer argument, defaulting
 |      to one million.
 |      Note: it's tempting to calculate mean and standard deviation
 |      from the result vector and report these.  However, this is not
 |      very useful.  In a typical case, the lowest value gives a
 |      lower bound for how fast your machine can run the given code
 |      snippet; higher values in the result vector are typically not
 |      caused by variability in Python's speed, but by other
 |      processes interfering with your timing accuracy.  So the min()
 |      of the result is probably the only number you should be
 |      interested in.  After that, you should look at the entire
 |      vector and apply common sense rather than statistics.

> if __name__=='__main__':
>    from timeit import Timer
>    for y in range(5):
>        t = Timer("proper_divisors_sum1(500000)", "from __main__
> import proper_divisors_sum")
>        print round(t.timeit(number=10000),3)
> Thanks,
> Dick
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

More information about the Tutor mailing list