Comprehension with two variables - explanation needed

Dan Stromberg drsalists at gmail.com
Mon Nov 24 19:42:06 EST 2014


On Sun, Nov 23, 2014 at 8:42 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> On Sun, 23 Nov 2014 08:45:39 -0800, Rustom Mody wrote:
>> First a one-line solution in haskell
>>
>> sieve (p:xs)   =    p:sieve [x | x <- xs, x `mod` p /= 0]
>
> Don't use that! That is a horribly inefficient way to generate primes.
>
> Mathematically, it is a version of Euler's Sieve. It is sometimes wrongly
> described as "Sieve of Eratosthenes", but that is wrong. Due to it's
> horrible performance, Melissa O'Neill calls this the "Sleight on
> Eratosthenes":

I don't read Haskell, but here's a Sieve (or at least I thought it was
a Sieve) and a few other prime-related things:
http://stromberg.dnsalias.org/~dstromberg/primes/



More information about the Python-list mailing list