First page Back Continue Last page Overview Graphics

A more Challenging Example

Calculation of the prime numbers up to 100:

>>> noprimes = [j for i in range(2, 8) for j in range(i*2, 100, i)]

>>> primes = [x for x in range(2, 100) if x not in noprimes]

>>> print(primes)

[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]

>>>

From Wikipedia