Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder7.xlned.com!newsfeed.xs4all.nl!newsfeed2.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'from:addr:yahoo.co.uk': 0.04; 'string': 0.09; 'boring': 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; 'language.': 0.14; "wouldn't": 0.14; '"key': 0.16; '10000000': 0.16; 'argument.': 0.16; 'discussion.': 0.16; 'indexerror:': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:bit': 0.16; 'unimportant': 0.16; 'index': 0.16; 'language': 0.16; 'wrote:': 0.18; 'obviously': 0.18; 'fit': 0.20; 'header:User-Agent:1': 0.23; '---': 0.24; 'skip:" 20': 0.27; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; '"",': 0.31; 'awards': 0.31; 'file': 0.32; 'probably': 0.32; '(most': 0.33; "i'd": 0.34; 'version': 0.36; 'being': 0.38; 'to:addr:python-list': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'most': 0.60; 'free': 0.61; 'viruses': 0.61; 'range': 0.61; 'protection': 0.63; 'our': 0.64; 'antivirus': 0.68; 'obvious,': 0.91; 'ware': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: A curious bit of code... Date: Thu, 13 Feb 2014 21:14:09 +0000 References: <4cc09129-43ee-4205-a24c-03f92b594abc@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: host-78-146-8-178.as13285.net User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 In-Reply-To: X-Antivirus: avast! (VPS 140213-0, 13/02/2014), Outbound message X-Antivirus-Status: Clean 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: 50 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1392326068 news.xs4all.nl 2916 [2001:888:2000:d::a6]:49465 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:66245 On 13/02/2014 21:01, Neil Cerutti wrote: > On 2014-02-13, Zachary Ware wrote: >> In a fit of curiosity, I did some timings: >> >> 'and'ed indexing: >> >> C:\tmp>py -m timeit -s "key = ''" "key[0] == '<' and key[-1] == '>'" >> 1000000 loops, best of 3: 0.35 usec per loop >> >> C:\tmp>py -m timeit -s "key = ''" >> 1000000 loops, best of 3: 0.398 usec per loop >> >> C:\tmp>py -m timeit -s "key = 'test>'" "key[0] == '<' and key[-1] == '>'" >> 1000000 loops, best of 3: 0.188 usec per loop >> >> C:\tmp>py -m timeit -s "key = 'test'" "key[0] == '<' and key[-1] == '>'" >> 10000000 loops, best of 3: 0.211 usec per loop >> >> C:\tmp>py -m timeit -s "key = ''" "key[0] == '<' and key[-1] == '>'" >> Traceback (most recent call last): >> File "P:\Python34\lib\timeit.py", line 292, in main >> x = t.timeit(number) >> File "P:\Python34\lib\timeit.py", line 178, in timeit >> timing = self.inner(it, self.timer) >> File "", line 6, in inner >> key[0] == '<' and key[-1] == '>' >> IndexError: string index out of range > > The corrected version > > key and key[0] == '<' and key[-1] == '>' > > probably still wins the Pretty Unimportant Olympics. > Exactly how I'd write it. To me it wins awards for being most boring and most obvious, obviously YMMV or we wouldn't be having this discussion. Or argument. Or contradiction :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com