Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed4.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.015 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'subject:number': 0.09; 'works.': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'itertools': 0.16; 'subject:skip:m 10': 0.16; 'wrote:': 0.18; 'skip:p 40': 0.19; 'import': 0.22; 'cc:addr:python.org': 0.22; 'instead.': 0.24; 'paul': 0.24; 'cc:2**0': 0.24; 'header:In- Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'usually': 0.31; 'idea,': 0.31; 'prints': 0.31; 'subject:all': 0.32; "i'd": 0.34; 'but': 0.35; 'received:google.com': 0.35; '14,': 0.36; 'yield': 0.36; 'pm,': 0.38; 'bad': 0.39; 'first': 0.61; '2015': 0.84; 'subject:find': 0.84; 'to:none': 0.92 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:cc :content-type; bh=FROECJp3msCrZZtLtbP658zLjyThmTilVQADc0J/k4Q=; b=bvh9CfXHQEIjTY3aj2UDzaYFJx0TmhT7ZxlsdOs+NU71Fe4qrvZHNJ8QE51YFcwPma Dz8GaEnmcsJV6ZzbL8w6ecfgfQyAQLntsjvPEzoahUWTUE0+2xrhJ+o/oxz8GaWxxreN +fA/m8ev3cD9ZFkwEf4SBzwEYIodcQZgtAQnV26Bo/4Dgsv7hPd0+x39wip28vrTbGqi 406P74o2QfQxXucw4Z4aHFEMaYbSFqge3ueHJjE3xgsqv4qZLV7ErBDKhkTAar3ine1a 5ibpuHNIshK1qLGlXCuLGdX4qjut2hKrrUpKAQfX0WghajG6qepI2JrowHmF5mNknZMh MksQ== MIME-Version: 1.0 X-Received: by 10.42.90.208 with SMTP id l16mr22538032icm.59.1428979663290; Mon, 13 Apr 2015 19:47:43 -0700 (PDT) In-Reply-To: <87egnnzb0k.fsf@jester.gateway.sonic.net> References: <890bd388-f50a-4dec-9ef5-27715427472a@googlegroups.com> <55288135$0$12997$c3e8da3$5496439d@news.astraweb.com> <87egnrb3il.fsf@jester.gateway.sonic.net> <87619387c0.fsf@elektro.pacujo.net> <90a8e07c-adb3-499f-8971-4ea49f6aea4b@googlegroups.com> <87lhhx7r44.fsf@elektro.pacujo.net> <87zj6czt84.fsf@jester.gateway.sonic.net> <87vbh0zow3.fsf@jester.gateway.sonic.net> <87r3rozjjp.fsf@jester.gateway.sonic.net> <552b6e78$0$12985$c3e8da3$5496439d@news.astraweb.com> <87egnnzb0k.fsf@jester.gateway.sonic.net> Date: Tue, 14 Apr 2015 12:47:43 +1000 Subject: Re: find all multiplicands and multipliers for a number From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20 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: 19 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1428979666 news.xs4all.nl 2872 [2001:888:2000:d::a6]:38455 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:88937 On Tue, Apr 14, 2015 at 12:42 PM, Paul Rubin wrote: > Just for laughs, this prints the first 20 primes using Python 3's > "yield from": > > import itertools > > def sieve(ps): > p = ps.__next__() > yield p > yield from sieve(a for a in ps if a % p != 0) > > primes = sieve(itertools.count(2)) > print(list(itertools.islice(primes,20))) Small point: Calling dunder methods is usually a bad idea, so I'd change this to "p = next(ps)" instead. But yep, that works... inefficiently, but it works. ChrisA