Pythonにおけるfilterの応用例−Etherふるい法による素数の求め
742 ワード
def _int_iter():# 3
n = 1
while True:
n = n + 2
yield n
def _not_divisible(n):#
return lambda x:x % n > 0
def primes():
yield 2 # 2
it = _int_iter() #
while True:
n = next(it) #
yield n
it = filter(_not_divisible(n), it) #
for n in primes():# ,
if n < 1000:
print(n)
else:
break