X-FeedAbuse: http://nntpfeed.proxad.net/abuse.pl feeded by 195.154.70.45 Path: csiph.com!usenet.pasdenom.info!nntpfeed.proxad.net!news.redatomik.org!newsfeed.xs4all.nl!newsfeed1.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'python,': 0.02; 'from:addr:yahoo.co.uk': 0.04; 'languages,': 0.04; 'python)': 0.05; 'failing': 0.07; 'memory.': 0.07; 'suddenly': 0.07; 'transform': 0.07; 'counting': 0.09; 'high-level': 0.09; 'integers': 0.09; 'iterate': 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; 'terms,': 0.09; 'worked,': 0.09; 'python': 0.11; 'language.': 0.14; 'all?': 0.16; 'before!': 0.16; 'denote': 0.16; 'index.': 0.16; 'iterating': 0.16; 'loop.': 0.16; 'looping': 0.16; 'porting': 0.16; 'pythonic': 0.16; 'range,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'all.': 0.16; 'language': 0.16; 'wrote:': 0.18; 'acquired': 0.19; '>>>': 0.22; 'example': 0.22; 'coding': 0.22; 'saying': 0.22; 'header:User-Agent:1': 0.23; 'integer': 0.24; 'typical': 0.24; 'earlier': 0.24; 'equivalent': 0.26; 'values': 0.27; 'header:X-Complaints-To:1': 0.27; 'header :In-Reply-To:1': 0.27; 'tried': 0.27; 'point': 0.28; 'change,': 0.30; 'code': 0.31; '>>>>': 0.31; 'fault': 0.31; 'overhead': 0.31; 'anyone': 0.31; 'probably': 0.32; 'up.': 0.33; 'implemented': 0.33; 'actual': 0.34; 'agree': 0.35; 'convert': 0.35; 'done.': 0.35; 'but': 0.35; 'there': 0.35; 'really': 0.36; 'ram': 0.36; 'doing': 0.36; "didn't": 0.36; 'seconds': 0.37; 'too': 0.37; 'list': 0.37; 'performance': 0.37; 'massive': 0.38; 'to:addr :python-list': 0.38; 'issue': 0.38; 'bad': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'most': 0.60; 'numbers': 0.61; 'took': 0.61; 'range': 0.61; 'simply': 0.61; 'simple': 0.61; 'our': 0.64; 'charset:windows-1252': 0.65; 'here': 0.66; 'fun?': 0.68; 'million': 0.74; 'introduce': 0.78; '100': 0.79; "'range'": 0.84; 'category.': 0.84; 'idiom': 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 20:15:24 +0100 References: <87k2wtvbx1.fsf@Equus.decebal.nl> <_M61x.477467$Ek.357048@fx07.am4> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: host-78-147-177-97.as13285.net 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: 62 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1430594149 news.xs4all.nl 2834 [2001:888:2000:d::a6]:44679 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:89787 On 02/05/2015 19:34, BartC wrote: > On 02/05/2015 17:39, Mark Lawrence wrote: >> On 02/05/2015 17:17, BartC wrote: >>> On 02/05/2015 16:40, Mark Lawrence wrote: > > >>>> 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? >>> >>> Your example is the equivalent of 'forall' in other languages, where you >>> iterate over the values of some collection of data. >>> >>> I agree that most for-loops in Pythonic code probably fall into that >>> category. >>> >>> But for looping over a simple integer range, then using 'range' to >>> denote the range (and build a list as it used to do), was how it was >>> done. And earlier on people would have been porting coding code to >>> Python at which point a straightforward 'for i=a to b' loop suddenly >>> acquired a substantial overhead it didn't have before! >>> >> >> All you are saying is that they didn't bother reading the docs and >> learning how to write a *PYTHON* for loop. Failing that don't bother >> using range, just directly convert your (say) C loop into Python. I >> really don't see any issue here at all. > > OK, so it's the programmer's fault if as fundamental a concept as a > for-loop ranging over integers is implemented inefficiently. He has to > transform it into high-level terms, or has to reconstruct it somehow > using a while-loop and an incrementing loop index. > > Now I understand (why Python has been beset for so long with performance > problems, if that is a typical attitude!). > > BTW, why did they introduce the 'xrange' thing; for fun? Or did someone > realise there might have been an issue after all? > > (I tried an empty loop counting to 1 billion in Python 2.x, using 'for i > in range'. It ran out of memory. Counting to 100 million instead, it > worked, but still used a massive 1.5GB RAM while doing so (and took 6 > seconds to count to 100M, not too bad for Python) > > Outside Python, it might typically take a few seconds to count to 1 > billion, and would use virtually no memory. > > Why would anyone want to loop over all those numbers instead of > iterating over actual data? For any number of reasons. Counting how many > happy numbers are in that range for one!) > I give up. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence