素數 生成器 惰性求值

  from itertools import count def _not_divisible(n): return lambda x: x % n > 0 # 獲取當前序列的第一個元素,而後刪除後面序列該元素倍數的數,而後構造新序列。 def primes(): yield 2 # 第1個素數是2 it = count(3, 2) # 3開始的奇數 whil
相關文章
相關標籤/搜索