Sieve of Eratosthenes in Python

So its Friday night and I’m looking for something cool to do with Python.  Hey, why not write a function to find all of the prime numbers between 2 and n.  Easy enough right?  Turns out its rather complicated.  There is an algorithm called Sieve of Eratosthenes which is used to find all of the prime numbers between 2 and n.  It works off the notion that a multiple of every number you encounter starting at 2 is not a prime number.  It continues incrementing and eliminating multiples until all you have left are prime numbers.  Its pretty intuitive, though not the most efficient for large lists, because the algorithm spends most of its time searching lists and eliminating multiples.

Sieve of Eratosthenes

In code:

Python 3 Code

How could you optimize this?

Source: WikiPedia | Zeno’s Parcel Service

 

New Design

Well, as you can see, I am going through a minor redesign.  I wanted to move to a more traditional WordPress based website.  Things will probably continue to change over the next few weeks.  Thanks for understanding.

As always, let me know what you think!