Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Antoon Pardon Newsgroups: comp.lang.python Subject: Re: Operator Precedence/Boolean Logic Date: Thu, 23 Jun 2016 12:54:55 +0200 Lines: 29 Message-ID: References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <576b5ea3$0$1595$c3e8da3$5496439d@news.astraweb.com> <576B96C0.2040106@rece.vub.ac.be> <87a8icgw0d.fsf@elektro.pacujo.net> <4e388a43-0191-4a48-8517-3ee3bdc50910@googlegroups.com> <871t3ogti9.fsf@elektro.pacujo.net> <576BAB88.3030407@rece.vub.ac.be> <87oa6sfczf.fsf@elektro.pacujo.net> <576BBFFF.3070504@rece.vub.ac.be> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de VkyEKG5Xu2MweytiH4n1rwOks20rKhiomtd4Nn9md7PQ== 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; 'else:': 0.03; 'method.': 0.05; 'received:134': 0.05; 'except:': 0.07; 'method,': 0.07; 'def': 0.13; 'emptiness': 0.16; 'received:ac.be': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'element': 0.18; 'of.': 0.18; 'try:': 0.18; '>>>': 0.20; 'see:': 0.22; 'this:': 0.23; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'see,': 0.27; 'correct,': 0.29; 'raise': 0.29; 'subject:/': 0.30; 'received:be': 0.30; 'maybe': 0.33; 'class': 0.33; 'url:python': 0.33; 'common': 0.33; 'except': 0.34; 'gives': 0.35; 'could': 0.35; 'false': 0.35; 'quite': 0.35; 'something': 0.35; 'but': 0.36; 'needed': 0.36; 'url:org': 0.36; 'structures': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'method': 0.37; 'data': 0.39; 'application': 0.39; 'to:addr:python.org': 0.40; 'url:3': 0.60; 'guaranteed': 0.67; 'theoretical': 0.72; 'pardon': 0.84; 'schreef': 0.84; 'url:datamodel': 0.84; 'url:reference': 0.91 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ArgIAHYeUleGuA9G/2dsb2JhbABehBBLATG8XyKFcAKCAAEBAQEBAWaEbQEBBCNVEQsaAgUWCwICCQMCAQIBRRMGAgKIKw6xP40+g1sBAQgBAQEBHgWBAYUmhE2FDII1glkFmEWBV4QsiCGJM4Vpj1JUg3BsAYoRAQEB User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Icedove/38.8.0 In-Reply-To: <87oa6sfczf.fsf@elektro.pacujo.net> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <576BBFFF.3070504@rece.vub.ac.be> X-Mailman-Original-References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <576b5ea3$0$1595$c3e8da3$5496439d@news.astraweb.com> <576B96C0.2040106@rece.vub.ac.be> <87a8icgw0d.fsf@elektro.pacujo.net> <4e388a43-0191-4a48-8517-3ee3bdc50910@googlegroups.com> <871t3ogti9.fsf@elektro.pacujo.net> <576BAB88.3030407@rece.vub.ac.be> <87oa6sfczf.fsf@elektro.pacujo.net> Xref: csiph.com comp.lang.python:110403 Op 23-06-16 om 11:53 schreef Marko Rauhamaa: > Antoon Pardon : > >> Op 23-06-16 om 11:10 schreef Marko Rauhamaa: >>> The __len__ method is not guaranteed to execute in O(1). See: >>> >>> >> ht=__len__#object.__len__> >> As far as I can see, neither is the __bool__ method. > Correct, but in the absence of an __empty__ method, __bool__ gives the > class the best opportunity to check for emptiness quickly. > > This is not only a theoretical concern. It's quite common for data > structures not to maintain an element count because it's extra baggage > that's not always needed and any application could keep a track of. > However, an emptiness check is often trivial. Maybe something like this: def empty(sq): try: iter(sq).next() except StopIteration: return False except: raise TypeError else: return True