Path: csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'ignored': 0.07; 'over,': 0.07; 'subject:two': 0.07; 'append': 0.09; 'builtin': 0.09; 'generators': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:into': 0.09; 'used.': 0.09; 'jan': 0.12; 'itself.': 0.14; '12:57': 0.16; 'builtins': 0.16; 'iterator': 0.16; 'objects.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'subject:based': 0.16; 'ignore': 0.16; 'wrote:': 0.18; 'wed,': 0.18; '>>>': 0.22; 'memory': 0.22; 'header :User-Agent:1': 0.23; 'question': 0.24; 'pass': 0.26; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'statement': 0.30; 'subject:list': 0.30; 'code': 0.31; 'constant': 0.31; 'operations.': 0.31; 'yields': 0.31; 'could': 0.34; 'problem': 0.35; 'something': 0.35; 'objects': 0.35; 'there': 0.35; 'sequence': 0.36; 'yield': 0.36; 'useful': 0.36; 'subject:?': 0.36; 'should': 0.36; 'skip:o 20': 0.38; '8bit%:86': 0.38; 'needed': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'does': 0.39; '12,': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'received:173': 0.61; 'simply': 0.61; 'first': 0.61; 'here': 0.66; 'phil': 0.84; 'received:fios.verizon.net': 0.84; 'usage.': 0.84; 'yielded': 0.84; '2013': 0.98 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Split a list into two parts based on a filter? Date: Wed, 12 Jun 2013 14:47:24 -0400 References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Gmane-NNTP-Posting-Host: pool-173-75-251-66.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130307 Thunderbird/17.0.4 In-Reply-To: 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: 35 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1371062857 news.xs4all.nl 15916 [2001:888:2000:d::a6]:60099 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:47829 On 6/12/2013 12:57 PM, F=C3=A1bio Santos wrote: > Why is there no builtin to consume a generator? I find that odd. There are several builtins than consume generators -- and do something=20 useful with the yielded objects. What you mean is "Why is there no=20 builtin to uselessly consume a generator?" The question almost answers=20 itself. A generator generates objects to be used. > On Wed, Jun 12, 2013 at 5:28 PM, Serhiy Storchaka = wrote: >> 12.06.13 09:32, Phil Connell =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=B2= (=D0=BB=D0=B0): >>> You could equivalently pass the generator to deque() with maxlen=3D0 = - >>> this consumes the iterator with constant memory usage. >> any((new_songs if s.is_new() else old_songs).append(s) for s in songs)= The problem here is that the generator generates and yields an unwanted=20 sequence of None (references) from the append operations. The proper=20 loop statement for s in songs: (new_songs if s.is_new() else old_songs).append(s) simply ignores the None return of the appends. Since it does not yield=20 None over and over, no extra code is needed to ignore what should be=20 ignored in the first place. --=20 Terry Jan Reedy