A dumb question about a class

Dustan DustanGroups at gmail.com
Sun Aug 12 20:35:21 EDT 2007


On Aug 12, 5:09 pm, Steven Bethard <steven.beth... at gmail.com> wrote:
>      def iter_primes():
>          # an iterator of all numbers between 2 and +infinity
>          numbers = itertools.count(2)
>
>          # generate primes forever
>          while True:
>
>              # get the first number from the iterator (always a prime)
>              prime = numbers.next()
>              yield prime
>
>              # remove all numbers from the (infinite) iterator that are
>              # divisible by the prime we just generated
>              numbers = itertools.ifilter(prime.__rmod__, numbers)

This is kind of OT (from the thread), but in this iter_primes
function, numbers is becoming an ifilter of an ifilter of an ifilter
of an ifilter of an ifilter of an ifilter of... Is that really at all
efficient for larger numbers (millions or billions, or even bigger)?




More information about the Python-list mailing list