On Sat, 11 Feb 2006 12:43:23 +0000, Ian Bygrave wrote:
> p,r=[],range(2,99)
> while r:p,r=p+r[:1],[x for x in r if x%r[0]]
> 
> And the result's in p.

Well, given a hypothetical new function 'sieve'

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]+tail

The prime generation can be reduced to:

from operator import *
sieve(mod,range(2,99))

Is there any precedent for such a function, or any other uses?
 
--Ian Bygrave

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to