The code shows a fast prime number generator using a sieve algorithm. It looks at only odd numbers. Technically 1 and 2 are prime numbers too, since they are only divisible by unity and themselves, exceptions are made for 1 and 2. Zero and negative numbers return an empty list.

Note:

The official definition for a prime number is any natural number [B]greater than 1[/B] that has the two divisors 1 and itself. So, we are leaving the 1 out!

This is not a generator object in the Python sense. It is a function that generates a list of prime numbers.

Note: see modified/corrected code at:

[url]http://www.daniweb.com/forums/post1254825.html#post1254825[/url]

For much improved speed see ...

https://www.daniweb.com/software-development/python/code/434136/fast-prime-list-functions

*Edited 2 Years Ago by vegaseat*