Path: csiph.com!usenet.pasdenom.info!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed3a.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; '(at': 0.04; 'from:addr:yahoo.co.uk': 0.04; 'default.': 0.09; 'enormous': 0.09; 'executed': 0.09; 'lawrence': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'rod': 0.09; 'seemed': 0.09; 'python': 0.11; 'language.': 0.14; 'bytecode': 0.16; 'callable': 0.16; 'finney': 0.16; 'instruction.': 0.16; 'iteration': 0.16; 'iteration,': 0.16; 'iterator': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'language': 0.16; 'wrote:': 0.18; 'looked': 0.18; 'seems': 0.21; '>>>': 0.22; 'creating': 0.23; 'header:User-Agent:1': 0.23; 'effort.': 0.24; 'values': 0.27; 'header:X-Complaints-To:1': 0.27; 'header:In- Reply-To:1': 0.27; 'fixed': 0.29; 'change,': 0.30; 'fastest': 0.30; 'writes:': 0.31; 'languages': 0.32; 'ago': 0.33; 'maybe': 0.34; 'created': 0.35; 'something': 0.35; 'but': 0.35; 'executing': 0.36; 'method': 0.36; 'turn': 0.37; 'list': 0.37; 'being': 0.38; 'sometimes': 0.38; 'ben': 0.38; 'to:addr:python- list': 0.38; 'itself': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'even': 0.60; 'eventually': 0.60; 'numbers': 0.61; 'simply': 0.61; 'simple': 0.61; 'first': 0.61; 'times': 0.62; 'making': 0.63; 'our': 0.64; 'million': 0.74; "'range'": 0.84; 'idiom': 0.84; 'iterative': 0.84; 'received:as9105.com': 0.84; 'received:dsl.as9105.com': 0.84; 'received:dynamic.dsl.as9105.com': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: l = range(int(1E9)) Date: Sat, 02 May 2015 16:40:44 +0100 References: <87k2wtvbx1.fsf@Equus.decebal.nl> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: 80-44-198-46.dynamic.dsl.as9105.com User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 In-Reply-To: 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: 51 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1430581268 news.xs4all.nl 2950 [2001:888:2000:d::a6]:53387 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:89774 On 02/05/2015 16:26, BartC wrote: > On 30/04/2015 18:20, Ben Finney wrote: >> Jon Ribbens writes: > >>> If you use xrange() instead of range() then you will get an iterator >>> which will return each of the numbers in turn without any need to >>> create an enormous list of all of them. >> >> If you use Python 3 instead of the obsolescent Python 2, the ‘range’ >> callable has this sensible behaviour by default. > > When I first looked at Python 20 or so years ago this seemed to be the > standard way of writing a for-loop: > > for i in range(N): > .... > > I remember being completely astonished at the time that 'range' actually > created a list of values from 0 to N-1. > > Python was already known to be slow yet it deliberately crippled itself > by using just about the slowest method imaginable of executing a simple > iterative loop? By first creating a list of a million objects! > > And sometimes you weren't even interested in the values but just wanted > to execute something N times so it was a wasted effort. > > That was eventually fixed with xrange, but why do it like that in the > first place? > > (At the time, I was creating bytecode languages as part of the > applications I was writing. An empty for-loop executed just one bytecode > per iteration, and it was also the fastest bytecode instruction. An > empty for-loop executed three Python bytecodes per iteration last time I > looked. It seems that Python used to like making a rod for its own back.) > I first started maybe 14 years ago and the standard way of writing a for loop was, and still is:- for item in items: When did this change, or has it always been this way and you were simply using an idiom from other languages? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence