def eratosthenes(firstCandidate=2):
    """
    Yields the sequence of prime numbers via the Sieve of Eratosthenes.
    rather than creating a fixed list of a range (z) and crossing out
    multiples of sequential candidates, this algorithm stores primes under
    their next possible candidate, thus allowing the generation of primes
    in sequence without storing a complete range (z).

    create a dictionary. each entry in the dictionary is a key:item pair of
    the largest (key) largest multiple of this prime so far found : (item)
    the prime. the dictionary only has as many entries as found primes.

    if a candidate is not a key in the dictionary, it is not a multiple of
    any already-found prime; it is thus a prime. a new entry is added to the
    dictionary, with the square of the prime as the key. the square of the prime
    is the next possible multiple to be found.

    to use this generator, create an instance and then call the .next() method
    on the instance


    >>> a = sieve.eratosthenes()
    >>> next(a)
    2
    >>> next(a)
    3


    We can also specify a starting value for the sequence, skipping over
    initial primes smaller than this number:


    >>> a = sieve.eratosthenes(95)
    >>> next(a)
    97
    >>> next(a)
    101
    """
    D = {}
    q = 2
    while True:
        p = D.pop(q, None)
        if p is not None:
            nextMult = p + q
            while nextMult in D:
                nextMult = nextMult + p
            D[nextMult] = p
        else:
            nextMult = q * q
            D[nextMult] = q
            if q >= firstCandidate:
                yield q
        q = q + 1
