November 11, 2011

A recent exercise generated (sorry) a discussion of generators in the comments, so in today’s exercise we will take a look at generators. The recent exercise that used a priority queue in place of the array in the Sieve of Eratosthenes works well with generators; in fact, Mike’s contributed solution used a Python generator.

Your task is to rewrite the prime number generator of the previous exercise to return primes using a generator instead of a list. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.


Pages: 1 2