showell30 at yahoo.com
Wed Jun 13 01:13:10 CEST 2007
--- Steven Bethard <steven.bethard at gmail.com> wrote:
> Steve Howell wrote:
> > --- George Sakkis <george.sakkis at gmail.com> wrote:
> >> from itertools import count, ifilter
> >> def sieve():
> >> seq = count(2)
> >> while True:
> >> p = seq.next()
> >> seq = ifilter(p.__rmod__, seq)
> >> yield p
> > Is there a way to broaden the problem somehow, so
> > it can be a longer solution and further down on
> > page, and so that I can continue to enforce my
> > somewhat arbitrary rule of ordering examples by
> > long they are?
> How about we just comment it better?
> import itertools
> def iter_primes():
> # an iterator of all numbers between 2 and
> numbers = itertools.count(2)
> # generate primes forever
> while True
> # generate the first number from the
> # which should always be a prime
> prime = numbers.next()
> yield prime
> # lazily remove all numbers from the
> iterator that
> # are divisible by prime we just selected
> numbers = itertools.ifilter(prime.__rmod__,
> I think that's 17-ish, though you could shrink it
> down by removing some
> of the spaces.
Actually, just one small caveat--I'd still want the
program to print out the results. I think I've
followed that convention for all the other programs.
Be a better Heartthrob. Get better relationship answers from someone who knows. Yahoo! Answers - Check it out.
More information about the Python-list