Home

On Aug 12, 5:09 pm, Steven Bethard <steven.beth...@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)?

previous
next

Re: split a string of space separated substrings - elegant solution?
Re: Combine two dictionary...
Re: gui toolkits: the real story? (Tkinter, PyGTK, etc.)
Re: C++ syntax expressed in toot-toot diagrams?
Re: SIGBUS, Bus error.
Pajacyk
Krwinka
Mam Marzenie
Rodzic Po Ludzku
Podaruj Zycie