primes = [i for i in range(2,100) if True not in [i % j == 0 for j in range(2,i)]]
P.S. 0012 hrs CST: My wife pointed out that I need only test half of the numbers between 1 and i. The new code is faster :)
primes = [i for i in range(2,100) if True not in [i % j == 0 for j in range(2,int(i / 2 + 1))]]
No comments:
Post a Comment