Shortest prime number program

Ian Bygrave ian at bygrave.me.uk
Sat Feb 11 08:45:19 EST 2006


On Sat, 11 Feb 2006 13:33:58 +0000, Ian Bygrave wrote:

> Well, given a hypothetical new function 'sieve'

which should have been:

def sieve(f,l):
    if not l:
        return l
    head,tail=l[0],l[1:]
    def filter_func(x):
        return f(x,head)
    tail=filter(filter_func,tail)
    return [head]+sieve(f,tail)

> The prime generation can be reduced to:
> 
> from operator import *
> sieve(mod,range(2,99))

--Ian Bygrave




More information about the Python-list mailing list