Path: csiph.com!weretis.net!feeder6.news.weretis.net!feeder4.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!fu-berlin.de!uni-berlin.de!not-for-mail From: Matt Wheeler Newsgroups: comp.lang.python Subject: Re: The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?) Date: Thu, 24 Mar 2016 14:22:28 +0000 Lines: 38 Message-ID: References: <8737rvxs89.fsf@elektro.pacujo.net> <56e7483d$0$1608$c3e8da3$5496439d@news.astraweb.com> <56ef9787$0$1516$c3e8da3$5496439d@news.astraweb.com> <56f02196$0$1588$c3e8da3$5496439d@news.astraweb.com> <56f3f09a$0$1595$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de EVm2P9Ia2zloJTuU7WUUQAD30yqmYLvW1U5m5c/qAgQQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.010 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; '(ie.': 0.09; '-1,': 0.09; 'semantics': 0.09; 'subject:which': 0.09; 'python': 0.10; 'index': 0.13; '0):': 0.16; '14:04,': 0.16; '2016': 0.16; '>on': 0.16; 'closely.': 0.16; 'element.': 0.16; 'problem).': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:?)': 0.16; 'to:name:python list': 0.16; 'wrote:': 0.16; "wouldn't": 0.16; 'element': 0.18; 'refers': 0.18; 'skip:` 10': 0.18; '(like': 0.23; 'header:In-Reply-To:1': 0.24; "doesn't": 0.26; 'not.': 0.27; 'message-id:@mail.gmail.com': 0.27; 'array': 0.29; "i'd": 0.31; 'point': 0.33; "d'aprano": 0.33; 'steven': 0.33; 'list': 0.34; 'received:google.com': 0.35; 'clear': 0.35; "isn't": 0.35; 'but': 0.36; 'list,': 0.36; 'received:209.85': 0.36; 'keyword': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'itself': 0.38; 'received:209': 0.38; 'delete': 0.38; 'building': 0.38; 'to:addr:python.org': 0.40; 'where': 0.40; 'subject:The': 0.61; 'more': 0.63; 'march': 0.64; 'results': 0.66; 'sound': 0.72; 'bounded': 0.84; 'from:addr:m': 0.84; 'presumably': 0.84; 'clearing': 0.91; 'do:': 0.91 X-Virus-Scanned: Debian amavisd-new at membrane.funkyhat.net X-Gm-Message-State: AD7BkJJhBpF0ibUQn0l8ui+P9RX4Bp4I04YZ6hps5A8st3qO0naQcEma1ruddPYkvuKLDGnnnexHuUD6jlPfbA== X-Received: by 10.112.210.200 with SMTP id mw8mr3530206lbc.16.1458829368254; Thu, 24 Mar 2016 07:22:48 -0700 (PDT) In-Reply-To: X-Gmail-Original-Message-ID: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:105616 On 24 March 2016 at 14:04, BartC wrote: >On 24/03/2016 13:50, Steven D'Aprano wrote: >> for i in range(len(mylist)-1, -1, 0): >> del mylist[i] > > That's wouldn't be I'd call clearing a list, more like destroying it > completely! Look more closely. The semantics of using the del keyword with an index are to delete that element. The list isn't destroyed, it just has each element removed in turn. The point is that one can just do `mylist.clear()` > How would you actually clear a list by traversing it (ie. not just building > a new one)? > > This doesn't work: > > for x in L: > x=0 > > as each x only refers to the value in each element of L, not the element > itself (like the pass-by-reference problem). > > I'd presumably have to do: > > for i in range(len(L)): > L[i]=0 That doesn't clear the list, that results in a list of the same length where every element is 0. That might sound like the same thing if you're used to a bounded array of ints, for example, but in Python it's very much not. -- Matt Wheeler http://funkyh.at