MCPcopy Create free account
hub / github.com/ActiveState/code / primegen

Function primegen

recipes/Python/576410_Lazy_Lists/recipe-576410.py:128–134  ·  view source on GitHub ↗
(lst)

Source from the content-addressed store, hash-verified

126 #prime numbers in a lazy list.
127 @lazylist
128 def primegen(lst):
129 yield 2
130 for candidate in itertools.count(3): #start at next number after 2
131 #if candidate is not divisible by any smaller prime numbers,
132 #it is a prime.
133 if all(candidate % p for p in lst.computed()):
134 yield candidate
135 primes = primegen() #same for primes- treat it like an infinitely long list
136 #containing all prime numbers.
137 print(fibs[0], fibs[1], fibs[2], primes[0], primes[1], primes[2])

Callers 1

recipe-576410.pyFile · 0.70

Calls 3

allFunction · 0.85
countMethod · 0.45
computedMethod · 0.45

Tested by

no test coverage detected