Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.049 X-Spam-Evidence: '*H*': 0.90; '*S*': 0.00; 'subject:two': 0.07; 'cc:addr:python-list': 0.11; '23,': 0.16; 'cc:name:python list': 0.16; 'haskell,': 0.16; 'to:addr:pearwood.info': 0.16; "to:name:steven d'aprano": 0.16; 'wrongly': 0.16; 'wrote:': 0.18; 'cc:addr:python.org': 0.22; '(or': 0.24; 'cc:2**0': 0.24; 'least': 0.26; 'header:In-Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; "d'aprano": 0.31; 'steven': 0.31; 'subject:with': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'version': 0.36; 'described': 0.36; 'that!': 0.36; 'url:org': 0.36; 'sometimes': 0.38; 'nov': 0.38; 'subject:needed': 0.38; 'pm,': 0.38; 'read': 0.60; 'subject:skip:C 10': 0.61; 'first': 0.61; 'due': 0.66; 'horrible': 0.84; 'inefficient': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=oZAFWVXeJCSpZqecdo1icOCDJRgJNrcOuqYfAiNojGU=; b=b0gl/EYKQajTFN+iUVMgDVIR/IJ5ap39aGCRbFubXIFlH2mEcEmm605ZjVqYmosQO3 3u6R3qs3g4/WVwHsfcYm9IZQ/1Y0HwUZf+E/ERfVLsjYlklXcN4KetNeoupwY/0PpTjv ZKU7lojTsy7gQESPd0TGVEHVIQRUqGkSZalQb6Vj6eVmhfXiH+Lr2cdUcW/wkWIALTiq 5k3EgHFQS49+FmDH9KOD/KiLdmoSb2+8WUs+W38Ah+iRj3qGGLEYFBYfKvcn1Drlu4iK b+2z7bb5xR7yorVXnsH9YwCaEnzwTWEOVl8zljhL5mYZ73KntQ4vKjp8872rQQHIUJUt 43hQ== MIME-Version: 1.0 X-Received: by 10.112.201.72 with SMTP id jy8mr23193847lbc.65.1416876126143; Mon, 24 Nov 2014 16:42:06 -0800 (PST) In-Reply-To: <5472b74d$0$12979$c3e8da3$5496439d@news.astraweb.com> References: <002501d00733$6995dce0$3cc196a0$@gmail.com> <07f25264-1286-4d98-820c-949dba711248@googlegroups.com> <5472b74d$0$12979$c3e8da3$5496439d@news.astraweb.com> Date: Mon, 24 Nov 2014 16:42:06 -0800 Subject: Re: Comprehension with two variables - explanation needed From: Dan Stromberg To: "Steven D'Aprano" Content-Type: text/plain; charset=UTF-8 Cc: Python List X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 16 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1416876136 news.xs4all.nl 2867 [2001:888:2000:d::a6]:36861 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:81477 On Sun, Nov 23, 2014 at 8:42 PM, Steven D'Aprano 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/