Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'method,': 0.07; 'objects.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'terry': 0.09; '(should': 0.16; 'hint': 0.16; 'iterable': 0.16; 'iterators': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'subject:optimization': 0.16; 'wrote:': 0.17; 'jan': 0.18; '>>>': 0.18; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'am,': 0.27; 'header:X-Complaints-To:1': 0.28; 'subject:list': 0.28; '>>>>': 0.29; 'call.': 0.30; 'to:addr:python-list': 0.33; 'christian': 0.34; 'too.': 0.35; 'next': 0.35; 'received:org': 0.36; 'but': 0.36; 'method': 0.36; 'subject:: ': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'subject:-': 0.40; 'header:Received:5': 0.40; 'easy': 0.60; 'range': 0.60; 'received:fios.verizon.net': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Interesting list() un-optimization Date: Thu, 07 Mar 2013 15:34:33 -0500 References: <20130306215735.649932ee@bigbox.christie.dr> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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/20130215 Thunderbird/17.0.3 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: 23 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1362688500 news.xs4all.nl 6864 [2001:888:2000:d::a6]:51940 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:40821 On 3/7/2013 11:20 AM, Christian Heimes wrote: > But iterators have a length hint method that are used for some > optimizations and preallocations, too. This is easy when the base iterable has a length method, as do range objects. >>>> i = iter(range(10)) >>>> i.__length_hint__() > 10 And the length_hint can (should be) decremented with each next call. >>> next(i); next(i) 0 1 >>> i.__length_hint__() 8 -- Terry Jan Reedy