def gen_primes():
D = {}<EOL>q = <NUM_LIT:2><EOL>while True:<EOL><INDENT>if q not in D:<EOL><INDENT>yield q<EOL>D[q * q] = [q]<EOL><DEDENT>else:<EOL><INDENT>for p in D[q]:<EOL><INDENT>D.setdefault(p + q, []).append(p)<EOL><DEDENT>del D[q]<EOL><DEDENT>q += <NUM_LIT:1><EOL><DEDENT>
Generate an infinite sequence of prime numbers.