SimplePrograms challenge

Steve Howell showell30 at yahoo.com
Tue Jun 12 19:35:31 EDT 2007


--- Steven Bethard <steven.bethard at gmail.com> wrote:

> On 6/12/07, Steve Howell <showell30 at yahoo.com>
> wrote:
> > --- Steven Bethard <steven.bethard at gmail.com>
> wrote:
> > > import itertools
> > >
> > > def iter_primes():
> > >      # an iterator of all numbers between 2 and
> > > +infinity
> > >      numbers = itertools.count(2)
> > >
> > >      # generate primes forever
> > >      while True
> > >
> > >          # generate the first number from the
> > > iterator,
> > >          # 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__,
> > > numbers)
> > >
> > > I think that's 17-ish, though you could shrink
> it
> > > down by removing some
> > > of the spaces.
> >
> > No, that's perfect.  Do you want me to post it, or
> do
> > you want the honors?
> 
> Go for it.
> 

Done:

http://wiki.python.org/moin/SimplePrograms (example
20)

Thanks, George and Steve!





 
____________________________________________________________________________________
Need Mail bonding?
Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users.
http://answers.yahoo.com/dir/?link=list&sid=396546091



More information about the Python-list mailing list