[Tutor] Help Optimise Code

Kent Johnson kent37 at tds.net
Thu Dec 4 19:10:39 CET 2008


On Thu, Dec 4, 2008 at 11:38 AM, Jörg Wölke <joewoe at fsmail.de> wrote:

> #!/usr/bin/env python
>
> l=10000*[1]
> for i in range(2,len(l)):
>    if l[i] == 1:
>       print i
>           for j in range(i+1,len(l)):
>               if j%i == 0:

for j in range(2*i, len(l), i):
would be much faster, avoiding all the division.

Kent


More information about the Tutor mailing list