SimplePrograms challenge

George Sakkis george.sakkis at gmail.com
Tue Jun 12 18:25:26 EDT 2007


On Jun 11, 5:56 pm, Steve Howell <showel... at yahoo.com> wrote:

> Hi, I'm offering a challenge to extend the following
> page by one good example:
>
> http://wiki.python.org/moin/SimplePrograms
>
> Right now the page starts off with 15 examples that
> cover lots of ground in Python, but they're still
> scratching the surface.  (There are also two Eight
> Queens implementations, but I'm looking to fill the
> gap in lines-of-code, and they're a little long now.)
>
> I'm looking for a good 16-line code example with the
> following qualities:
>
>   1) It introduces some important Python concept that
> the first 15 programs don't cover.
>
>   2) It's not too esoteric.  Python newbies are the
> audience (but you can assume they're not new to
> programming in general).
>
>   3) It runs on Python 2.4.
>
>   4) It doesn't just demonstrate a concept; it solves
> a problem at face value.  (It can solve a whimsical
> problem, like counting rabbits, but the program itself
> should be "complete" and "suitably simple" for the
> problem at hand.)
>
>   5) You're willing to have your code reviewed by the
> masses.
>
>   6) No major departures from PEP 8.
>
> Any takers?
>
> -- Steve

I love the 7-line version of the prime number generator by Tim
Hochberg at the last comment of http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/117119:

from itertools import count, ifilter
def sieve():
    seq = count(2)
    while True:
        p = seq.next()
        seq = ifilter(p.__rmod__, seq)
        yield p


I suspect that it violates your second rule though :)

George




More information about the Python-list mailing list